Readonly for field when 'Edit', but not for 'New'

Readonly for field when 'Edit', but not for 'New'

mcflausemcflause Posts: 10Questions: 0Answers: 0
edited July 2012 in Editor
I have a text field 'Product' I want the user to be able to use the 'New' button and be able to insert the name into the text field 'Product'. But when the user goes to 'Edit' the product I would like the 'Product' field to be only read only, but still allow them to edit the other fields.

I know its possible to do [code]"type": "readonly"[/code] but this applies to both 'New' and 'Edit' functions of the editor.

Is this possible?

Thanks.

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Hi,

    It isn't currently possible to dynamically switch between field types, however, there are two options that will, hopefully, do the job for you:

    1. You could enable and disable the field when the form is opened (the onInitEdit and onInitCreate events). Each field has an enable and disable method which can be used, so on edit you would disable it - effectively giving you a readonly field. Something like:

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

    2. You could use the onInitEdit and onInitCreate event again to add and remove the field, or to show and hide two matching fields (one readonly and one read/write) - but I think that option 1 is probably better.

    Allan
This discussion has been closed.