It looks like you're new here. If you want to get involved, click one of these buttons!
i have been trying to use the select2 form type, the problem is that additional options like "maximumSelectionLength" wont work
$fields['states'] = array('type' => 'select2', 'maximumSelectionLength'=>5,'maximumInputLength'=>3);
it outputs the select2 but the maximumSelectionLength does not take effect.
any help please
Comments
Does it work if you attach data attributes to the element like in the following:
Sorry for the delayed response, Let me give that a try
Thanks for the code but I tried it and it still did not work.
$fields['states'] = array('type' => 'select2', 'data' => array('maximum-selection-length' => 2, 'maximum-input-length'=>3));
Another thing you could try is adding the following to the fuel/application/config/custom_fields.php to overwrite the existing configuration for the
select2
custom field:Note the
js_params
addition to the configuration. That gets converted to a JSON object which gets passed to the select2 as a configuration object in the custom_fields.js select2 function.Is it possible to add js_param from field definition in the model or the block directly?
I'd like to use select2 with an ajax request.
Not at this time. It's only within the definition of the field type. However, a new field type could probably be created that has
maximumSelectionLength
andmaximumInputLength
as field parameters. The function could be modeled off the Fuel_custom_fields::select2 method that would allow for those parameters to be passed (THIS IS REALLY ROUGH UNTESTED CODE):And then in then in a similar javascript function as one found in the custom_fields.js
fuel.fields.select2
javascript function, you would add in those as options perhaps using thedata-options
passed to the form element:Again, this is me riffing here and rough code, but hopefully to give you an idea of how it could be modified. If you get it working and think it would be a good update to FUEL, let me know and send a pull request.
Thanks for some input, that might makes some things easier or keep some config in the right place. I'll check it out.
I made a gist with a working approach (it's quite messy, but people who understand Fuel should be able to follow) https://gist.github.com/marcus-at-localhost/16262b75a9a82854fd82474de7d0eb47
I got it working with Select2 v3 the current version in fuel - but it didn't work well with the inline edit buttons. (Select2 v3 needs a hidden form field for the ajax stuff, instead of select and that throws off the fuel inline edit implementation.)
With Select2 v4 seems to work ok. I completely overwrite the select2 field to use v4 everywhere. So it works seamless.
https://gist.github.com/marcus-at-localhost/16262b75a9a82854fd82474de7d0eb47#file-custom_fields-php-L66
Right now I'm just evaluating my options, so it's not thought through and I don't feel comfortable to send those pull requests ;-).
Where I'm struggling right now is that the Select2 fields are not getting rendered if they are in a Block Layout Field and initially hidden. But that's a different problem.
Thanks. m.