5098 Posts in 1518 Topics by 1115 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 763 Views |
-
Using AjaxUniqueTextField

9 July 2011 at 9:01am
Hi,
I'm trying to set up a site using SilverStripe and I want to add a field to pages that must be unique, it looks like I can do this using the AjaxUniqueTextField class but I can't find any documentation on how to use it.
The constructor takes several arguments but I don't know what several of them should be, could someone please point me towards some documentation or provide an example of a text field that must be a unique value.
$name - The database field this form field is for.
$title - What to display to the user.
$restrictedField - ?
$restrictedTable - ?
$value - ?
$maxLength - Max length the input can be.
$validationURL - ?
$restrictedRegex - A regex the input must match to be valid?public static $db = array(
'page_id' => 'varchar(32)'
);function getCMSFields() {
$fields = parent::getCMSFields();$fields->addFieldToTab('Root.Content.Main', new AjaxUniqueTextField('page_id', 'Page Id', $restrictedField, $restrictedTable, $value, 32, null, $restrictedRegex), 'Content');
return $fields;
}
Cheers,James Bench
-
Re: Using AjaxUniqueTextField

10 July 2011 at 1:23pm
AjaxUniqueTextField is one of those old legacy field types that have been around but no one really used it. I even thought we had deprecated that a while back but doesn't look like it.
Taking a stab in the dark (and looking at the file)
* $restrictedField - a string with the name of the database field you want force uniqueness on. e.g "Title"
* $restrictedTable - a string with the name of the database that field exists in, e.g "SiteTree"
* $value - the default value of the field (just like {TextField->value}
* $validationURL - optional, callback url, e.g "home/validate/foo" which returns a bool. Must be true for validation to pass.
* $restrictedRegex - yep, like you said, a regex that must pass for validation to pass. -
Re: Using AjaxUniqueTextField

11 July 2011 at 3:00am
What should I be using instead of AjaxUniqueTextField if it's a legacy class?
Cheers,
James Bench
-
Re: Using AjaxUniqueTextField

11 July 2011 at 9:19am
What should I be using instead of AjaxUniqueTextField if it's a legacy class?
Your own code, but try the AjaxUniqueTextField and see if you can get it to work, may just do exactly what you need!
| 763 Views | ||
|
Page:
1
|
Go to Top |


