How to make a select2 readonly? #649
-
I have a select2 with these attributes 'attributes' => [ disabled is working, but I cannot use this because browser will not send its value as payload of the POST but readonly is not working. user can still change selected value ! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @realtebo there are some issues with readonly that we are aware. We started adding them to the crud api here: #4443 but noticed that alot of fields required additional customizations for the read only, especially the PRO ones. 1 - with readonly the user can still navigate with the keyboard unless we implement keyboard blockers too. This is the screenshoot from PRO fields like select2 when we attempt to add the readonly: We decided to let the idea rest for a while. So what I would advise you for now, if you really need to keep the field a select2 readonly is to either:
crud.field('select2').onChange(function(field) {
// field.$input is the jquery wrapped element
field.$input.on( ... );
}).change(); We maybe revisit the reaonly PR's in future, in that case you can later delete the custom file or the crud js script and use the core functionality for it. Cheers |
Beta Was this translation helpful? Give feedback.
-
The problem is raised here due to another bug about form operation and morph fields I open a new issue in a few minutes. Actually we need a workaround because it's vital for our project [long sad story as always due to stupidity of customers] |
Beta Was this translation helpful? Give feedback.
Hey @realtebo there are some issues with readonly that we are aware. We started adding them to the crud api here: #4443 but noticed that alot of fields required additional customizations for the read only, especially the PRO ones.
1 - with readonly the user can still navigate with the keyboard unless we implement keyboard blockers too.
2 - some fields couldn't be "readonly" and we needed to disable them anyways to simulate readonly.
This is the screenshoot from PRO fields like select2 when we attempt to add the readonly:
We decided to let the idea rest for a while.
So what I would advise you for now, if you really need to keep the field a select2 readonly is to either: