corenzan / readonly.js Goto Github PK
View Code? Open in Web Editor NEWMake form controls - even <select> - read-only.
License: MIT License
Make form controls - even <select> - read-only.
License: MIT License
Suggest add on change event:
$('input').on('change, function() { // update corresponding hidden value of input with same name $('input:hidden[data-sham="'+ $(this).name +'"]').val(''); })
in case the value is programmatically changed.
e.g. $('select').val('changed value').trigger('change')
Out of curiosity: would this support multiple selects?
select checkbox compent unavailability
Hi Corenzan,
Looking to readonly.js, when used with select, you turn them readonly creating an input with the same name attribute than the select.
When serializing, jQuery do it using the name attribute for select, so instead having no value (serializeArray don't get value when the element is disabled), you get the value from this hidden input.
But when user change select value when select element is disabled, identifiying the select by value (in case of programmaticaly change without direct user interaction), then it turns that this hidden input is not update.
The idea would perhaps to set a trigger that update this hidden input value when the select value is modified on readonly mode.
What do you think ?
readonly([...])
is thrown "invalid argument" error even though it's an array of elements.
If we have something like the following:
<input type="checkbox" name="something" value="1" />
...
if( isset( $_POST['something'] ) && '1' === $_POST['something'] ) {
//checkbox was checked
}
setting the checkbox to readonly will result in a hidden input being created with value="1". In the above example this will result in the assumption that the checkbox was checked whether or not it actually was. I assume the same would be true for type=radio.
The workaround I applied was to add the following to line 13 of the script
if(target.type === 'checkbox' && ! target.checked){
return;
}
Im using jquery 2.0.3 and trying to use this functionality in order to make a select (second element) readonly if a certain value of a select (first element) option is chosen or editable if another option is chosen with the same select element. But I couldnt make it work correctly. It turns readonly in the right way but can make it editable after beeing readonly
Line 116 in 29df904
The call to entryPoint
in the dist version of the code differs from the src version in a way that actually is broken. By passing in _this
the dist version is supplying a jQuery object as the target, which does meet the valid argument requirements and so throws the invalid argument
error.
The dist
file should be updated to reflect the correct logic found in the src version of the code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.