Ajax dropdown and select one

How to add a default "Please Select" option to an AJAX dropdown in ChronoForms.

Overview

The issue occurs because the dropdown lacks a default placeholder option, forcing users to manually deselect and reselect to trigger dependent fields.
Modify the AJAX event code to insert a "Please Select" option at the beginning of the options array before populating it with dynamic data.

Answered
ChronoForms v5
Tw Twincarb 05 Apr, 2017
Hi,

I have a form with multiple linked dropdowns, an issue I have is when the user selects the first option, the second option is poputlated, if the user wants to select the first option in the second box they have to deselect the first option and reselect it. This then populates section 3 correctly.

What do I need to add to my Ajax event to add "Please Select" to be the first option. I am assuming it's to the $options options array.

<?php
$options = array();
if ( !$form->data['ajax_select_org'] || count($form->data['ajax_select_org']) < 1 ) {
  // no result was found
  $options[] = 'Select Above First';
} else {
  foreach ( $form->data['ajax_select_org'] as $d ) {

    $options[$d['id_org']] = $d['org_name'];
  }
}
echo json_encode($options);
?>


Thanks in advance for your help.

Dave
Gr GreyHead 05 Apr, 2017
Answer
Hi Dave,

Please try
  $options[] = 'Select Above First';
} else {
  $options[] = 'Please Select'; // << add this line
  foreach ( $form->data['ajax_select_org'] as $d ) {

Bob
Tw Twincarb 05 Apr, 2017
Thanks Bob,

That's solved the issue🙂 and makes the data entry flow.

Regards,

Dave
This topic is locked and no more replies can be posted.