21301 Posts in 5736 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 256 Views |
-
DataObject validation for duplicate record

14 January 2013 at 3:30pm
Hi,
I would like to check if a certain record already exist before adding it in the table. Show meaningful error message
to the user too if it failes. I am using DataObject and ModelAdmin to manage those tables.class Country extends DataObject {
static $db = array('CountryName');
....
//check if country exist before saving
....
}
Is there anyone who would like to share some idea how to accomplish this?
Thanks!
-
Re: DataObject validation for duplicate record

15 January 2013 at 1:18pm
The netefxvalidator works well with modeladmin, for ss 2.4 and 3.0
The unique rule is what you are looking for.You have to add the validator in a function getCMSValidator
Download: https://github.com/lx-berlin/NetefxValidator
Documentation: http://www.netefx.de/Silverstripe-NetefxValidator.phpLx
-
Re: DataObject validation for duplicate record

6 April 2013 at 7:44pm
Hello lx,
Can you share your thoughts on vlaidation on CMS (backend) please.Assuming I have a Product DataObject, containing name, price and date fields,
how can I validate these fields while I'm adding a new product at the backend.A piece of sample code for validator function would be very helpful.
Thank you very much -
Re: DataObject validation for duplicate record

8 April 2013 at 12:20am
Please read this thread for a code example...
-
Re: DataObject validation for duplicate record

8 April 2013 at 12:40am
Hi soolan,
here are some example rules, that are a little bit more complex than just "required".
I hope they are working.regards
lxclass Product extends DataObject {
...
public function getCMSValidator() {
$rule_Name_required = new NetefxValidatorRuleREQUIRED ("Name", "The name of the product is required.");
$rule_Price_higher_zero = new NetefxValidatorRuleGREATER ("Price", "You need to enter a price higher than 0.", null, "0");
$rule_Date_required = new NetefxValidatorRuleREQUIRED ("Date", "The date is required.");
$rule_Date_in_future = NetefxValidatorRuleFUNCTION("Date", "The date has to be in the future.", null,array('NetefxValidatorLibraryDate', 'DateIsMinDaysAfterToday', array('date' => 'Date', 'min' => 1)));$validator = new NetefxValidator($rule_Name_required, $rule_Price_higher_zero, $rule_Date_in_future, $rule_Date_required);
return $validator;
}...
}
| 256 Views | ||
|
Page:
1
|
Go to Top |




