10375 Posts in 2190 Topics by 1707 members
| Go to End | ||
| Author | Topic: | 2200 Views |
-
Re: Userforms adapted?

8 June 2011 at 11:25pm
I managed to get this working by editing UserDefinedForm.php...
This "if" statement inside getRequiredFields():
if ($field->Required) {
$rules[$field->Name] = array_merge(array('required' => true), $field->getValidation());
$required->addRequiredField($field->Name);
}became:
if ($field->Required) {
$rules[$field->Name] = array_merge(array('required' => true), $field->getValidation());
$required->addRequiredField($field->Name);
} else {
if ($field->getValidation()) {
$rules[$field->Name] = $field->getValidation();
}
}Not sure if that's really the best way of doing it but it seems to get the job done. Now, to figure out how to make the error messages more relevant...
-
Re: Userforms adapted?

9 June 2011 at 12:29am
Sort-of-fixed my error message by adding this function to my custom numeric field.
/**
* Return the error message for this field. Either uses the custom
* one (if provided) or the default SilverStripe message
*
* @return Varchar
*/
public function getErrorMessage() {
$standard = 'Please enter a number';$errorMessage = ($this->CustomErrorMessage) ? $this->CustomErrorMessage : $standard;
return DBField::create('Varchar', $errorMessage);
} -
Re: Userforms adapted?

18 June 2011 at 12:59am
I was also having a problem with validation; if a user entered something into a numeric field and then blanked it again, the error message would remain and the form wouldn't submit unless the field was completed. The field wouldn't even attempt to validate with "required" set to "false", so I cooked something up to overcome this, which I'll post for the benefit of anyone Googling this:
inside getValidation():
$options['number'] = true;
$options['required'] = "function(element) {return element.val() != ''}";You can also use "digits" instead of "number" if you want to make it integer-only.
-
Re: Userforms adapted?

18 June 2011 at 3:48pm
Hey Max, Great work digging into these issues. Is there anyway you could put together a ticket on open.silverstripe.org and list everything you did (try making a diff file if you can). Sounds like this would be a good feature to include in the release.
-
Re: Userforms adapted?

20 June 2011 at 11:58pm
Thanks, Will- it still needs work (i18n, non-JS validation, etc.) but I will try to put a ticket together at some point. Great module, by the way.
| 2200 Views | ||
| Go to Top |


