pwfans Posted March 13, 2020 Share Posted March 13, 2020 Hello there, Anyone have solution for simple field type text with dropdown support ? basically i need dropdown field type which can be filled also with custom text like this in html : <input type="text" list="predefined" name="customlist"> <datalist id="predefined"> <option value="option-A"> <option value="option-B"> <option value="option-C"> </datalist> The closest thing is Inputfield Selectize but it is too overkill, and Text Input Awesomplete which not dropdown but autocomplete. Thanks Link to comment Share on other sites More sharing options...
Robin S Posted March 14, 2020 Share Posted March 14, 2020 You could add the datalist to a normal text field using a hook in /site/ready.php: $wire->addHookBefore('InputfieldText::render', function(HookEvent $event) { /* @var InputfieldText $inputfield */ $inputfield = $event->object; $field = $inputfield->hasField; if($field && $field->name === 'my_field') { $inputfield->attr('list', 'my-list'); $inputfield->appendMarkup = <<<EOT <datalist id="my-list"> <option value="One"> <option value="Two"> <option value="Three"> </datalist> EOT; } }); 3 1 Link to comment Share on other sites More sharing options...
pwfans Posted March 16, 2020 Author Share Posted March 16, 2020 On 3/14/2020 at 2:28 PM, Robin S said: You could add the datalist to a normal text field using a hook in /site/ready.php: $wire->addHookBefore('InputfieldText::render', function(HookEvent $event) { /* @var InputfieldText $inputfield */ $inputfield = $event->object; $field = $inputfield->hasField; if($field && $field->name === 'my_field') { $inputfield->attr('list', 'my-list'); $inputfield->appendMarkup = <<<EOT <datalist id="my-list"> <option value="One"> <option value="Two"> <option value="Three"> </datalist> EOT; } }); Great ! i will use this for now, but module will be super great ! easier to maintain. Thanks a lot @Robin S Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now