Jump to content

Publishing a page only possible if obligatory fields are filled in.


vknt
 Share

Recommended Posts

I'm having this scenario: for my page to render properly, I need to have certain fields filled in. Is their a way to make fields obligatory? So that you can't publish the page when those fields are not filled in? As I would solve it now, I would start the template by checking if the fields are empty, and if so provide a default value. However, sometimes a default value is not a good option.

Any thought on how you would approach this?

Thx in advance!

Link to comment
Share on other sites

Hi there.

In recently published/uprdate roadmap, required field are planned for version 2.2 (source: http://processwire.com/about/roadmap/), so this feature should be available by the end of the year in the github build.

Right now, I would solve this by the default values + stepping on editors to do their work properly, or possibly, you could create module with outlined function below:


  •  
  • Hook to page::save (before)
     
  • Check whether the template fits, else do nothing [return;]
     
  • If it fits, check for existence of fields
     
  • If they are empty, cancel the save and return to page edit

To make this easy for editors, you could create small JS snippet, which locks save buttons, if your required fields are empty (with jQuery, this should be like 5 line snippet)

Link to comment
Share on other sites

I'm not sure how this would fit in the PW code base and philosophy (or maybe there are already things in place) but i think it would be great if there was some sort of validation library that ties into the field UI functionality and is also usable via API.

Let's say i'm making a site where eventually a couple of people will be allowed to add riders that will compete in a cycling event. A rider has a license number so i add an integer field to my rider template. Ideally i would want to make this field required but also make sure the number is in a certain range (e.g. between 1000 and 50.000), because i know numbers out of range are invalid.

It would be great if i was able to define (multiple) validation rules on my license number field in the UI. These options could go under the any of the existing tabs (details, input, advanced) or a new 'validation' tab. Maybe it could even be possible to define custom error messages for your rules right there. Off course one would have to consider multi-lang issues but i'm just thinking out loud. A user who tried to save a rider page without a license number, or a number outside of the defined range would get to see the error messages upon trying to save.

Some examples of different validation rules and options:

laravel.com/docs/start/validation

http://fuelphp.com/docs/classes/validation/validation.html

Link to comment
Share on other sites

We'll definitely be adding more validation rules for existing fieldtypes and this is something I've been doing incrementally and regularly. The integer fieldtype used to have min/max range options in PW1, and they'll be coming back in PW2. You may already see that some fieldtypes and inputfields carry more validation rules than others. I also think it would be good for me to get a few starting-point examples of fieldtypes/inputfields going to show you guys how simple it is to make your own too. For instance, if I need a field that has specific requirements for input, I take the route of copying one of the existing ones into /site/modules/, renaming it and modifying it to do what I need. It's easy, but not described anywhere so I'll work on a tutorial here soon.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...