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

Type: Discussion
Status: New
jchick
View Replies: View Best Answer
jordanlev replied on at Permalink Reply
jordanlev
Do you already have at least one other required field, or would this be the first one?
And what kind of field is it that you want to require -- a text field, a textarea, an image, etc.?
jchick replied on at Permalink Reply
jchick
I actually want to change a field from being required to not being required. It's a url field.
jordanlev replied on at Permalink Best Answer Reply
jordanlev
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.
jchick replied on at Permalink Reply
jchick
Thanks for the fast reply! Much appreciated. I figured it out.
keeasti replied on at Permalink Reply
keeasti
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.

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
jordanlev replied on at Permalink Reply
jordanlev
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:
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');
}
keeasti replied on at Permalink Reply
keeasti
Thanks Jordan,
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.
keeasti replied on at Permalink Reply
keeasti
Hi,

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() !== ''
jordanlev replied on at Permalink Reply
jordanlev
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).
keeasti replied on at Permalink Reply
keeasti
I thought it may be something to do with that ... I tried != as well but to no avail. Thanks again for your input :)

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.