Jump to:

5541 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Using AjaxUniqueTextField

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1181 Views
  • jebbench
    Avatar
    Community Member
    7 Posts

    Using AjaxUniqueTextField Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Using AjaxUniqueTextField Link to this post

    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.

  • jebbench
    Avatar
    Community Member
    7 Posts

    Re: Using AjaxUniqueTextField Link to this post

    What should I be using instead of AjaxUniqueTextField if it's a legacy class?

    Cheers,

    James Bench

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Using AjaxUniqueTextField Link to this post

    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!

    1181 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.