function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chirag_JoshiChirag_Joshi 

<apex:inputfield> tag not working with custom modal popup

I've a custom modal in which i have a pageblock section to create a Task for the sobjects i select.
The <apex:inputfield> is not binding with the sobject Task as I'am gettiing empty task values
Need help on this. How can i fix this?

VF Code:
<apex:form >
        <div id="simpleModalTask" class="modal">
            <div class="modal-content-TE">
                <div class="modal-header">
                    <span class="closeBtn">&times;</span>
                    <h2>Create Task</h2>
                </div>
                <div class="modal-body">
                    <center style="padding-left: 40px;">
                        <apex:pageBlock >
                            <apex:pageBlockSection columns="2">
                                <apex:repeat value="{!TaskFields}" var="fld">
                                    <apex:inputField value="{!massTask[fld]}"/>
                                </apex:repeat>
                            </apex:pageBlockSection>
                        </apex:pageBlock>
                        <br/><br/>
                    </center>
                </div>
                <div class="modal-footer">
                    <apex:commandbutton onClick="createTask()" value="Create" reRender="simpleModalTask" status="detailStatus"/> &nbsp;&nbsp;&nbsp;
                    <apex:commandbutton onClick="closepopTask()" value="Cancel" reRender="simpleModalTask"/>
                    <apex:actionFunction action="{!createMainTasks}" name="createTask" reRender="NoFieldPB,MainTablePB"/>
                    <apex:actionFunction name="cancel" reRender="NoFieldPB,MainTablePB"/>
                </div>
            </div>
        </div>       
    </apex:form>
JavaScript Code:
<script>
    // Get modal element
    var modalTask = document.getElementById('simpleModalTask');
    // Get close button
    var closeBtnTask = document.getElementsByClassName('closeBtn')[1];
    // Listen for close click
    closeBtnTask.addEventListener('click', closeModalTask);
    // Listen for outside click
    window.addEventListener('click', outsideClickTask);
    
    // Function to open modal
    function openModalTask(){
        
        modalTask.style.display = 'block';
    }
    
    // Function to close modal
    function closeModalTask(){
        modalTask.style.display = 'none';
    }
    
    // Function to close modal if outside click
    function outsideClickTask(e){
        if(e.target == modalTask){
            modalTask.style.display = 'none';
        }
    }
    
    function createTask(){
        createTask();
        modalTask.style.display = 'none';
    }
    
    function closepopTask(){
        cancel();
        modalTask.style.display = 'none';
    }
    document.onkeydown = function(evt) {
        evt = evt || window.event;
        var isEscape = false;
        if ("key" in evt) {
            isEscape = (evt.key == "Escape" || evt.key == "Esc");
        } else {
            isEscape = (evt.keyCode == 27);
        }
        if (isEscape) {
            modal.style.display = 'none';
            modalTask.style.display = 'none';
            modalEvent.style.display = 'none';
        }
    };
    </script>

Apex Code:
public PageReference createMainTasks(){
        if(selectedObj != null){
            List<Task> mainToTask = new List<Task>();
            for(MainRecordWrapperClass mwc: Paging.myData){
                if(mwc.isSelected){
                    System.debug(massTask); // This comes out to be empty
                    Task t = new Task();
                    t.Subject = massTask.subject;
                    t.WhoId = massTask.whoId;
                    t.Status = massTask.status;
                    t.ActivityDate = massTask.ActivityDate;
                    t.type = massTask.type;
                    t.WhatId = mwc.mainRecords.id;
                    mainToTask.add(t);
                }
            }
            
            try{
                insert mainToTask;
                massTask = new Task();
                instantiateMainObjLst();
            }catch(Exception e){
                System.debug('ERROR: ' + e.getcause() + ': ' + e.getmessage()); // Required field missing
                ApexPages.addMessages(e);
            }
        }
        return null;
    }

User-added image