Jump to content
pwfans

fieldt ype text with dropdown support

Recommended Posts

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

 

 

Share this post


Link to post
Share on other sites

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;
	}
});

 

  • Like 2

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...