0

I have Input type radio button inside my <apex:repeat> and on page load i want to check the radio button based on value provided in Constructor. I am using :

 <input type="radio" onclick="OnClickSelectDedupe('{!dedupe.Bcif_id__c}')" name="dedupe" id="{!dedupe.Bcif_id__c}"                                                                               checked ="{!oppData.Contact__r.bcif_id__c}"/>

But the last radio button is getting checked.I am even trying to check the value in VF page on load:

//bcifId is string which has the respective id to be checked.
 Public String bcifId{get;set;}
    function loadData() {
                document.getElementById('{!bcifId}').checked = true;
    }

ERROR: Cannot get checked value of NULL.

But its not finding the desired Id.

Code for reference below:

<tbody id="storebody">
    <apex:outputPanel rendered="{!isAppDedupeFound}">
    <tr>
        <td colspan="10" style="text-align: center;"><b>No Dedupe Records Found From Core Dedupe API!</b></td>
    </tr>
</apex:outputPanel>
<tr style="display:none;">
    <td>
        <apex:outputPanel rendered="{!isAppDedupeFound}">
            <apex:repeat value="{!dedupeListApp}" var="dedupe">
                <tr style="">
                    <td>
                        <!--<apex:commandButton value="Save" styleClass="slds-button  slds-button--brand"/>-->
                        <span class="slds-radio">
                            <!--<apex:selectRadio onclick="OnClickSelectDedupe('{!dedupe.Bcif_id__c}')"  id="coreDedupe" 
value="{!bcifId}"  layout="pageDirection"  borderVisible="false">

</apex:selectRadio>-->
                            <input type="radio" onclick="OnClickSelectDedupe('{!dedupe.Bcif_id__c}')" name="dedupe" id="{!dedupe.Bcif_id__c}"
                                   value="{!oppData.Contact__r.bcif_id__c}"/>
                            <label class="slds-radio__label" for="{!dedupe.Bcif_id__c}">
                                <span class="slds-radio_faux"></span>

                            </label>
                        </span>
                    </td>
                    <td>
                        <div>{!dedupe.Bcif_id__c}</div>
                    </td>
                    <td>
                        <div>{!dedupe.First_name__c}
                            {!dedupe.middle_name__c}
                            {!dedupe.last_name__c}
                        </div>
                    </td>

                    <td>
                        <div>{!dedupe.date_of_birth__c}</div>
                    </td>

                    <td>
                        <div>{!dedupe.mobile__c}</div>
                    </td>

                    <td>
                        <div>{!dedupe.addr1__c}</div>
                    </td>

                </tr>
            </apex:repeat>
        </apex:outputPanel>
    </td>
</tr>

</tbody>

UPDATED CODE:::

<apex:selectRadio onclick="OnClickSelectDedupe('{!dedupe.Bcif_id__c}')"  id="coreDedupe" 
    value="{!bcifId}"  layout="pageDirection"  borderVisible="false">

        </apex:selectRadio>


            Public String bcifId{

                get{
                    system.debug('bcifId '+bcifId);
                    if (bcifId == null) {
                        bcifId = oppData.Contact__r.bcif_id__c;  // default value
                        system.debug('bcifId '+bcifId);
                    }
                    return bcifId;
                } set;    


            }

Debug is printingRadioButton the proper value but the radio button is not selected and also one more issue with using <apex:selectRadio>. Please refer the image attached.

Some lines are getting added above the radio buttons i don't know whats that...

0

Why not use the built-in VF components?

<apex:selectRadio value="{!selectedRadioItem}">
   <apex:selectOptions value="{!radioItems}"/>
</apex:selectRadio>

with controller

public List<SelectOption> getRadioItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('A','A'));
        options.add(new SelectOption('B','B'));
        options.add(new SelectOption('C','C')); 
    return options;
}

public String selectedRadioItem {
   get{
    if (selectedRadioItem == null) {
       selectedRadioItem = 'B';  // default value
    }
    return selectedRadioItem;
   } set;
}
  • Hi @cropredy..Thanks for the response, I dont need options to be added so updated with your code given. Still the radio button is not selected. Please see updated code. – Deepak Agarwal Mar 5 '19 at 6:26
  • And i need to put that in a method.Sorry for wrong info its being called on button click not on Constructor. – Deepak Agarwal Mar 5 '19 at 6:39
  • Can anyone answer this please its an urgent requirement. – Deepak Agarwal Mar 13 '19 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.