Editor Forms Question 1: readonly when Editing, text when Adding possible

Editor Forms Question 1: readonly when Editing, text when Adding possible

jfeyjfey Posts: 10Questions: 0Answers: 0
edited August 2012 in Editor
I am using the Forms to Add/Edit/Delete single entries. For a NEW entry i like to be able to let the user enter a user name. Hence the field should be of type "text". But the same field should not be changed later on by the user via the Edit feature.

How can i do this?

cheers

Juergen

Replies

  • allanallan Posts: 51,954Questions: 1Answers: 7,882 Site admin
    Hi Juergen,

    In Editor 1.1, unfortunately this isn't trivial since it doesn't announce that the form is shown and in what state. However, Editor 1.2 is due for release tomorrow and will include new events which will be ideal for this, along with the API.

    Specifically the onInitCreate, onInitEdit and onInitRemove events could be used to modify fields. For example:

    [code]
    editor.on( 'onInitCreate', function () {
    editor.enable('name');
    } );

    editor.on( 'onInitEdit', function () {
    editor.disable('name');
    } );
    [/code]

    Having said that, it would be possible to use the onSubmit event in 1.1 to modify the data being sent to the server and simply remove the 'name' field. It isn't as nice a UI though...

    Allan
  • jfeyjfey Posts: 10Questions: 0Answers: 0
    Allan,

    This is super cool, and two super fast answers to my questions !! :-)
    Will check it out when V 1.2 is out.

    cheers

    Juergen
  • savasava Posts: 4Questions: 0Answers: 0
    Hi,

    A step further to this, is it possible to conditionally disable a field based on whether it has data in it?
    i.e. I have a DATE field and if that field has a value then I do not want it edited again only if it is blank should it be enabled.

    Does onInitEdit have access to test the field values?


    Thanks.
  • allanallan Posts: 51,954Questions: 1Answers: 7,882 Site admin
    Yes it does - you can use the `get` method ( http://editor.datatables.net/api/#get ) to get the value and then process it as you require (presumably using the `enable` and `disable` methods in this case.

    Allan
This discussion has been closed.