Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#816143
Per https://wiki.processmaker.com/3.2/Suggest_Control,
"When an end user is using a suggest control, it is not mandatory to select an option from the suggested options (SQL or/and Options). If the user enters text that is not included in the suggestions, the entered text will be stored in the variable."

Does anybody know a way to force the user to select from the suggested list? I'm already populating the list using SQL, but if the user wants to type in a value not from the suggested list, the control has no problem with it. I would rather not use a dropdown control for this, because I'm populating it with a list of all users and it would be a long list to scroll through.
#816153
If you have a list of fixed options, then there is a foolproof way to prevent the user from entering a custom value. If you are using an SQL query to populate the list of options in the suggest box, then the first field returned by your SQL query needs to be different from the second field returned by the query. That way, the JavaScript can check if the selected value is different from the label. If they are the same, then the code knows that the user entered a custom value, rather than selecting one of the provided options.

You can use JavaScript like this:
Code: Select all
$("#selectRecipient").setOnchange( function(newValue, oldValue) {
  if (newValue == '') {
    return true;
  }
  
  //check if the new value is in the list of fixed options:
  var aOptions = this.getInfo().options;
  console.log(aOptions);
  
  for (i in aOptions) {
    if (aOptions[i].value == newValue) {
      return true;
    }
  }
  
  //if the value matches the label, then it is a selected option and 
  //not a custom value entered by the user:
  if (newValue != this.getText()) { 
    return true;
  }
  
  //the user has entered a custom value, so display an alert
  alert("'"+newValue+"' is not in the list of options.\nPlease select from the list of options.");
  this.setValue('');
});
#817185
Thanks for the response Amos. Upon further testing this, I found that if the filtered results is reduced to 1 result, and I DON'T click on an option from the filtered list, it will not give off the alert. However, it will store the inputted string (rather than the only visible option).
Capture2.JPG
Capture2.JPG (7.21 KiB) Viewed 3669 times

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]