Page 1 of 1

setText and setValue is the same for suggest

Posted: Fri Apr 21, 2017 10:50 am
by ashkufaraz
Hi

I has a suggest that i want change value it
Code: Select all
$("#SetValue").click(function(){
	$("#User").setValue($("#USR_UID").getValue());
})
But setValue function change value and text suggest!
also setText function change value and text suggest!

how can change only value or only text of suggest?
(2.83 KiB) Downloaded 116 times

Re: setText and setValue is the same for suggest

Posted: Fri Apr 21, 2017 9:10 pm
by amosbatto
There is currently a bug in suggest boxes. You can set the value with setValue(), but it doesn't select one of the options.

I have created two workaround functions that you should use in place of setValue() and setText() with suggest boxes:
Code: Select all
//function to use in place of setText() with suggest boxes:
// if the ID of the suggest box is "selectUser" and its SQL query is: 
// SELECT USR_UID, USR_USERNAME FROM USERS
// then: selectOptionText('selectUser', 'admin');
function selectOptionText(suggestId, optionText) {
  var aOptions = getFieldById(suggestId).executeQuery();

  for (var i in aOptions) {
    if (aOptions[i].text.search(optionText) != -1) {
      $("[id='form["+suggestId+"_label]']").val( aOptions[i].text );
      $("[id='form["+suggestId+"]']").val( aOptions[i].value );
      return;
    }
  }
  //no match found in list of options so use setText():
  $("#"+suggestId).setText(optionText);
}

//function to use in place of setValue() with suggest boxes:
// if the ID of the suggest box is "selectUser" and its SQL query is: 
// SELECT USR_UID, USR_USERNAME FROM USERS
// then: selectOptionValue("selectUser", "00000000000000000000000000000001");
function selectOptionValue(suggestId, optionValue) {
  var aOptions = getFieldById(suggestId).executeQuery();

  for (var i in aOptions) {
    if (aOptions[i].value.search(optionValue) != -1) {
      $("[id='form["+suggestId+"_label]']").val( aOptions[i].text );
      $("[id='form["+suggestId+"]']").val( aOptions[i].value );
      break;
    }
  }
  //no match found in list of options so use setValue():
  $("#"+suggestId).setValue(optionValue);
}
Here is a sample DynaForm to demonstrate its use:
(2.7 KiB) Downloaded 127 times