HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Validating a year field

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#70463 (In Topic #14908)
Avatar

Community saint

I have a field in my Image Galleries catalog which I would like to validate to a 4-digit number start with "19" (ideally, I'd like to be able to specify a min year and max year). I saw the form-field filter tutorial but can't seem to make it work.

My URL is:

Code

http://xxxxxxxxx.com/cms/cms_catalogues/add_entry.htm?catalogue_name=image_galleries&category_id=18&keep_session=4715205&redirect=http%3A%3Aslash%3A%3Aslash%3Axxxxxxxxx.com%3Aslash%3Acatalogues%3Aslash%3Acategory%3Aslash%3Aimage-gallery%3Aslash%3Aportraits.htm%3Fcatalogue%3Dimage_gallery%3Aamp%3Akeep_session%3D4715205xxxxxxxxx

I tried creating a form-field filter in /data_custom/fields.xml as follows:

Code

<qualify pages="cms_catalogues" types="add" fields="Year painted">
      <minLength error="Entry too short">4</minLength>
      <maxLength error="Entry too long">4</maxLength>
   <!--   <possibilitySet error="Incorrect year">xxxx</possibilitySet>  -->
   </qualify>

Am I even close to getting this to work? Also, what would I use for the possibilitySet to make sure I get a year starting with "19" and containing all numbers?

Thanks for any help.

Bob
Back to the top
 
Posted
Rating:
#70488
Avatar

   <qualify pages="cms_catalogues" types="ad,_ad" fields="field_14">
         <minLength error="Entry too short">4</minLength>
         <maxLength error="Entry too long">4</maxLength>
      </qualify>

The possibilitySet value list would have to be 100 items long to work for what you wanted, we don't have support for any kind of regular expresion/wildcards here. For it to be a number, just make it a numeric field.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#70510
Avatar

Community saint

Thanks, Chris.

Silly that I didn't make the year an integer value since I had changed another field to to be a dropdown menu.

How much overhead is there in processing a possibilitySet with 90 to 100 entries?

Bob

Back to the top
 
Posted
Rating:
#70511
Avatar

No immediate answer comes to mind, sorry


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#70512
Avatar

Community saint

I'll just give it a try and see what happens. Since it is only an issue when entering new catalog entries, it won't matter too much if it takes a bit longer. I just want to make sure that people don't accidentally turn a 20th century painter into an Old World master.

Thanks for your help.
Back to the top
 
Posted
Rating:
#70556
Avatar

Community saint

Chris, how about adding a "fieldsAsInt" type attribute on the qualify tag as a simple fix.

That should be a trivial enhancement that can force type conversion where explicitly specified while maintaining comparability with existing xml filters.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70559
Avatar

Community saint

<qualify pages="cms_catalogues" types="ad,_ad" fields="field_14">
         <minLength error="Entry too short">4</minLength>
         <maxLength error="Entry too long">4</maxLength>
      </qualify>

Where do you find the field number? Is it only available when Short URLs is disabled?

Bob
Back to the top
 
Posted
Rating:
#70561
Avatar

Community saint

Hover your mouse over the "edit this" link and you will see ".../_edit_entry/7" etc.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70563
Avatar

Community saint

But isn't that the catalog record id rather than the catalog field id?
Back to the top
 
Posted
Rating:
#70564
Avatar

Community saint

Ah yes, sorry about that, miss read your question.

OK, the correct answer is: click on "edit this" and view the html of the edit page, and search for label for="field_ and that will take you directly to the fiend number and its name. Repeat search for each field as required.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70565
Avatar

Community saint

Thanks, temp. Now to try out by new field validation.

Bob
Back to the top
 
Posted
Rating:
#70567
Avatar

Community saint

I am getting the following error when trying to validate a field:

Code

fields.xml: not well-formed (invalid token)

This is the validation code which I copied from above, adjusting the field:

Code

<qualify pages="cms_catalogues" types="ad,_ad" fields="field_45">
      <minLength error="Entry too short>4</minLength>
      <maxLength error="Entry too long">4</maxLength>
   </qualify>

Can anyone point me in the right direction?

Thanks for any help.

Bob
Back to the top
 
Posted
Rating:
#70568
Avatar

Community saint

Missing quotes.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70569
Avatar

Community saint

Thanks, temp.

Made that change and no longer getting the XML warning. But the field is still not validating.

Below is the relevant source from the catalog entry page:

Code

<td id="required__field_45" class="dottedborder_barrier_b_required">
      <div id="error_field_45" style="display: none" class="input_error_here"></div>
      
      
         <div class="accessibility_hidden"><label for="field_45">Year painted</label></div>
      
      
         <input type="hidden" name="label_for__field_45" value="Year painted" />

So "field_45 is correct but I was still able to enter a three-digit year.

Below is the corrected validation code:

Code

<qualify pages="cms_catalogues" types="ad,_ad" fields="field_45">
      <minLength error="Entry too short">4</minLength>
      <maxLength error="Entry too long">4</maxLength>
   </qualify>

Any thoughts?

Bob
Back to the top
 
Posted
Rating:
#70573
Avatar

Community saint

I haven't looked at field validation before, but if I'm reading the xml as expected then I would have though you need to use a min/max lengths of 2 instead of 4.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70575
Avatar

Community saint

The field is "Year painted" so I would expect them to enter a 4-digit year (e.g., 1964).

At least, that's what I am trying to accomplish.

Bob
Back to the top
 
Posted
Rating:
#70576
Avatar

Community saint

Of course. I read too way too much into your "Old World master" & "still able to enter a three-digit year" comments and though you were trying to restrict it to double digits.

It sounds like the its not even associating the xml to the right field. So while the field name make be correct, maybe its the page name. How did you determine the page name?

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70578
Avatar

Community saint

temp1024 said

It sounds like the its not even associating the xml to the right field. So while the field name make be correct, maybe its the page name. How did you determine the page name?
Copied from Chris's first post in the thread. He seemed to be correcting my initial take on it.

Bob
Back to the top
 
Posted
Rating:
#70579
Avatar

Community saint

Fair enough. In that case I am out of ideas.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70580
Avatar

Community saint

Thanks, temp.

Maybe Chris can weigh in when he gets a chance.

Bob
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Expand