How do you set the text of a selected value using rbf api? - Forum - Rollbase - Progress Community

How do you set the text of a selected value using rbf api?

 Forum

How do you set the text of a selected value using rbf api?

This question is answered

I am trying to use the rbf_getpicklistcode and rbf_setpicklistcode APIs to do some field manipulation on a "New" page in Rollbase.  I have a custom button that will copy all the address fields on the page to another set of address fields.  Both my state and country are single select picklists.  So far, I can get and set the codes, but not the text on the screen of the newly set code.

If I simply set the text value of this field, it removes the drop down option and replaces everything with the text.

Any help would be greatly appreciated.

Verified Answer
  • Hello,

    After your rbf_setPicklistCode try to invoke change event on the <select>, I have this JQuery code to that.

    $("select[name='billing_state']").change();

    Hope this may help.

    Regards,

    Orchid

All Replies
  • Are you applying rbf_setPicklistCode API to read-only picklists? Please clarify.

  • No, they are not read only.  I am setting it to an editable picklist.  I'm basically trying to allow them to click a button to copy their shipping and billing address information.  I would like to leave it editable even if they say it is the same.

  • Hi,

    I am thinking if this State/Province field a dependent picklist to a Country picklist? If yes:

    1. Set the Country picklist first since State/Province picklist at first is empty
    2. Then, try to check the two State/Province if they have the same Code or Value, I do the checking via inspect element. This time my picklist has no Code. Assuming the two picklist has the same value.

    3. Get the first picklist's Value and Assign it to the second State/Province. See Code Below:

    
    
    <button onclick="copyState();"> Copy State </button>
    <script>
    	function copyState() {
    		/*---------------------------------------------------
    			if you are using Code instead of value, change:
    			rbf_getFieldValue --> rbf_getPicklistCode
    			rbf_setFieldValue --> rbf_setPicklistCode
    		----------------------------------------------------*/
    		var state1 = rbf_getFieldValue("state");
    		rbf_setFieldValue("State_Province_2", state1);
    	}
    </script>


    Hope this may help.

    Regards,

    Orchid

  • rbf_setFieldValue should work if you know field's value (numerical ID of your item). But rbf_setPicklistcCde() works as well if you know item's integration code (which is more meaningful). So I'm not sure what the original problem is.

  • Yes, I agree I would use rbf_setPicklistCode and rbf_getPicklistCode but I notice something on dependent picklist "State/Province" (default field when location was enabled) at first it has Code but when I change the country, the code just cleared and what remains are the value only that made the rbf_getPicklistCode and rbf_setPicklistCode unusable.

  • I am still having issues getting this to display the value in my picklist.  I have two sets of addresses on my screen: 

    I populate the shipping address section, then hit my Same as Shipping button.  The regular inputs are copied as expected, but the state does not get updated. 

    If I click on the state under the billing address, it defaults to Nebraska, so it appears to be getting the code correctly, just not the text value. 

    Here is the code I am using to set these values:

    $(document).ready(function() {
      	
      	$("#myButton").click(function() {
          	
          myAddress1 = rbf_getFieldValue("streetAddr1");
      		if (myAddress1 != '') {
          		rbf_setFieldValue("billing_address1", myAddress1);
              	rbf_setFieldDisabled("billing_address1", true);
          	} 
          	myAddress2 = rbf_getFieldValue("streetAddr2");
      		if (myAddress2 != '') {
          		rbf_setFieldValue("billing_address2", myAddress2);
              	rbf_setFieldDisabled("billing_address2", true);
          	}
          	myCity = rbf_getFieldValue("city");
      		if (myCity != '') {
          		rbf_setFieldValue("billing_city", myCity);
              	rbf_setFieldDisabled("billing_city", true);
          	}
            myCountry = rbf_getPicklistCode("country");
      		if (myCountry != '') {
          		rbf_setPicklistCode("billing_country", myCountry);
          	}
          	myState = rbf_getPicklistCode("state");
          	    	if (myState != '') {
          		rbf_setPicklistCode("billing_state", myState);
             
          	}
          	myZIP = rbf_getFieldValue("zip");
      		if (myZIP != '') {
          		rbf_setFieldValue("billing_zip", myZIP);
              	rbf_setFieldDisabled("billing_zip", true);
          	}
          	
        });
    });

  • Hello,

    After your rbf_setPicklistCode try to invoke change event on the <select>, I have this JQuery code to that.

    $("select[name='billing_state']").change();

    Hope this may help.

    Regards,

    Orchid

  • Thanks Orchid!  That did the trick.

  • That's Great! :)

    Cheers,

    Orchid