0

I have an options field which is sourced from an external json file using the following code.

$nsbooks_url = 'https://mysite.com/myjson.json';
$preoptions = json_decode(file_get_contents($nsbooks_url), TRUE);
$options = array_column($preoptions, 'Document Number');
\Drupal::cache()->set('nsbooks', $options);

The JSON file contains these lines.

[{
    "custid": "88149",
    "recordType": "salesorder",
    "Document Number": "SO7878"
}, {
    "custid": "89757",
    "recordType": "salesorder",
    "Document Number": "SO1226"
}]

In the webform, I have another field where the user enters their customer ID number. (custid in the JSON file.)

What I am trying to do is filter the JSON file so that only document numbers that match that customer ID number are shown as an option. How can I achieve this?

1 Answer 1

0

I think thats not possible without writing own code.

Try to alter the webform with the hook your_module_webform_submission_form_alter and add an ajax callback to the customer ID number field, which updates the options. To accomplish this, you can take a look at https://www.hashbangcode.com/article/drupal-9-cascading-ajax-select-forms.

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.