Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » getCMSFields_forPopup validation

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2175 Views
  • ScottiouS
    Avatar
    Community Member
    54 Posts

    getCMSFields_forPopup validation Link to this post

    I have a custom page which has a has_many relationship to a dataobject.

    These objects are displayed in a getCMSFields HasManyComplexTableField.

    I am running a function within onBeforeWrite() in the dataobject's class in order to validate a value which is entered before saving it to the DB. However if the value is not valid I have no way to notify the user. If I attempt to return any value from the onBeforeWrite function then it just hangs with the "saving..." button spinning.

    How can I send a meaningful response back to the user?

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: getCMSFields_forPopup validation Link to this post

    I don't have an exact answer, but maybe you can use these things:

    - LeftAndMain::ForceReload();
    (see http://api.silverstripe.com/cms/core/LeftAndMain.html, look at the comment at the bottom)

    - FormResponse: http://api.silverstripe.com/forms/core/FormResponse.html, which will output a message in the ajax way...

    Hope this can help somehow...

  • ScottiouS
    Avatar
    Community Member
    54 Posts

    Re: getCMSFields_forPopup validation Link to this post

    Thanks Dio5.. tried using FormResponse in the onBeforeWrite function but this doesn't return any value to the user. Perhaps I need to be returning values from elsewhere..

  • ScottiouS
    Avatar
    Community Member
    54 Posts

    Re: getCMSFields_forPopup validation Link to this post

    Ok, so here's my work around. Was the only way I could see to get information back to the user.

    Basically
    1) create an extra field on your dataObject called Response
    2) Add $fields->push( new ReadonlyField( 'Response', 'Response' ) ); to your getCMSFields_forPopup function.
    3) Then based on your response you want to send set it in onBeforeWrite with $this->Response = "Error - blah blah";

    This solution, although not ideal, works. The main problem is that the record is still saved. In my case this is not too much of a problem as I use the response field to filter whether or not to show an item on the front end of the CMS.

    And since the popup box stays open it gives the user another chance to correct the problem and then save again.

    2175 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.