for necessity I hide some fields, but I would like that when they are hidden they are not required. If I set requests (edit tag-> required) when they are not visible the added script crashes, how can I find it? I tried with jquery but it doesn’t work like that.
if (this.value == “1”) {
$(this).fields(“customfield1”).visible(true);
$(this).fields(“customfield1”).required(true);
$(this).fields(“customfield2”).visible(false);
$(this).fields(“customfield2”).required(false);
No need to set required like that. Fortunately, PHPMaker has handled the required fields (that you have already setup from “Fields” setup → “Edit Tag” pane → “Validation” → “Required” very good.
If you hide the required fields by using Javascript/jQuery code from “Client Scripts” section (Startup Script), then the generated built-in validation will handle this automatically. In other words, the hidden required fields will never call the generated built-in validation function.
Let’s see this code from the demo project, for example, from “modelsadd.php” file, the “Trademark” field is already setup as “Required” from the project side, and PHPMaker will generate the validation code as follows:
As you can see from this following part, PHPMaker will handle the Required fields nicely:
if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
that means: if the element exists and it is not hidden and it does not have the value (which is empty), then the validation will return the error message.
The conclusion is, for the required hidden fields, then that validation above will never been called. That’s the beauty of PHPMaker.
No need to set required like that. Fortunately, PHPMaker has handled the required
fields (that you have already setup from “Fields” setup → “Edit
Tag” pane → “Validation” → “Required” very good.
then it won’t work if I use Client-Side Event (Javascript)?do i have to rewrite all the code?
The conclusion is, for the required hidden fields, then that validation above will
never been called. That’s the beauty of PHPMaker.
if I hide the field (required) I can’t add the form. In 2020 it worked. how can i solve?
2021
fieldA required;
ew.events = {
“clienti”: {
“x_Anonimo”: { // keys = event types, values = handler functions
“change”: function(e) {
$(this).fields(“fieldA”).value(“”);
$(this).fields(“fieldA”).visible(false);
As I mentioned before, PHPMaker has handled it automatically from the generated built-in validation.
If you want to hide the required field, you should do that from “Startup Script” section, and not from the jQuery fields plugin.
For example, from the demo project, go to “suppliers” table, enable “Required” for “ContactTitle” field from its Fields setup, and then put this code in Startup Script of Edit page:
$(“#r_ContactTitle”).hide();
re-generate ALL the script files, and try to edit one of the records from Suppliers Edit page. As you can see, the “ContactTitle” field is now hidden, and this required hidden field will not be validated. In other words, PHPMaker v2021 also has handled it nicely.
but most of the fields I hide them dynamically with jQuery. Before in 2020 if I was hiding with jQuery the field was not requested now even if hidden is required. How can I solve since I have to hide them (and no longer mandatory) when other fields change in value?