How do I change a field from being "required"?
Permalink Browser Info Environment
Hi,
I've created a block and now the client has changed his mind about a field being required. Where in the block's code can I change this setting?
Thanks
I've created a block and now the client has changed his mind about a field being required. Where in the block's code can I change this setting?
Thanks
Type: | Discussion |
---|---|
Status: | New |
I actually want to change a field from being required to not being required. It's a url field.
Edit the "auto.js" file in the block's directory (it will be inside the top-level "blocks" folder on your server).
Each required field has a chunk of code in there. If you're not familiar with javascript at all or you aren't sure how to remove the proper code, you can post the contents of your auto.js file here and I'll tell you what to change.
Each required field has a chunk of code in there. If you're not familiar with javascript at all or you aren't sure how to remove the proper code, you can post the contents of your auto.js file here and I'll tell you what to change.
Thanks for the fast reply! Much appreciated. I figured it out.
Hi,
I was wondering how to check if a field is not empty.
I have two fields and trying to achieve an XOR function of sorts. ie. either one or the other should be filled and both can't be empty.
Field one is a Page select link and field 2 is an external URL link.
Here is what I tried but it doesn't seem to quite work in that it throws the 'Duplicate link' error when field one is empty and field 2 is not empty.
TIA
I was wondering how to check if a field is not empty.
I have two fields and trying to achieve an XOR function of sorts. ie. either one or the other should be filled and both can't be empty.
Field one is a Page select link and field 2 is an external URL link.
Here is what I tried but it doesn't seem to quite work in that it throws the 'Duplicate link' error when field one is empty and field 2 is not empty.
if (($('input[name=field_1_link_cID]').val() == '' || $('input[name=field_1_link_cID]').val() == 0) && ($('input[name=field_2_link_url]').val() == '')) { ccm_addError('Missing required link: Link to page OR to URL'); } if (($('input[name=field_1_link_cID]').val() !== '' || $('input[name=field_1_link_cID]').val() !== 0) && ($('input[name=field_2_link_url]').val() !== '')) { ccm_addError('Duplicate link: Link to page OR to URL'); }
TIA
I find that it helps to "untangle" tricky logic like this by setting some additional variables with useful names, then using those variables in the "if" statements.
For example:
For example:
var link1val = $('input[name=field_1_link_cID]').val(); var link2val = $('input[name=field_2_link_url]').val(); var link1IsEmpty = (link1val == '' || link1val == 0); var link2IsEmpty = (link2val == ''); if (link1IsEmpty && link2IsEmpty) { ccm_addError('Missing required link: Link to page OR to URL'); } else if (!link1IsEmpty && !link2IsEmpty) { ccm_addError('Duplicate link: Link to page OR to URL'); }
Thanks Jordan,
I'll give this a spin and let you know.
I had a butchers and found a 'fix' by doing the following:
But I am not sure I like it!
Curiously, if I change the first part to
then it doesn't work although I think it should.
I'll give this a spin and let you know.
I had a butchers and found a 'fix' by doing the following:
if (($('input[name=field_1_link_cID]').val().length > 1) && ($('input[name=field_2_link_url]').val() !== '')) { ccm_addError('Duplicate link: Link to page OR to URL'); }]
But I am not sure I like it!
Curiously, if I change the first part to
($('input[name=field_1_link_cID]').val() !== '')
then it doesn't work although I think it should.
Hi,
That worked a treat ... thanks again.
Bit puzzled though why
gives a different result to
That worked a treat ... thanks again.
Bit puzzled though why
!$('input[name=field_1_link_cID]').val() == ''
gives a different result to
$('input[name=field_1_link_cID]').val() !== ''
Not sure, but it might have to do with the difference between "==" vs. "===" (and similarly between "!=" and "!==") -- one is comparing "truthiness", and the other is comparing exact match of exact same data types. Since the first code snippet uses "==", it's just checking if two values are "equal-ish" (like the string "1" is equal to the integer 1), whereas the second code snippet uses "!==" so it's checking that the values are the same AND are of the same exact type (so the string "1" is NOT equal to the integer 1, because they are different data types).
I thought it may be something to do with that ... I tried != as well but to no avail. Thanks again for your input :)
And what kind of field is it that you want to require -- a text field, a textarea, an image, etc.?