Serenity: display all control to readonly according to a field value

Created on 16 Mar 2018  路  6Comments  路  Source: serenity-is/Serenity

how to make all controls readonly according to a field value

Most helpful comment

export class PayDialog extends Serenity.EntityDialog<PayRow, any> {
       .........................

        protected updateInterface() {
            super.updateInterface();
            if (!this.isNew()) {
                if (this.entity.Fact) {
                    Serenity.EditorUtils.setReadonly(this.element.find('.editor'), true);
                    this.element.find('sup').hide();
                    this.deleteButton.hide();
                    Serenity.EditorUtils.setReadonly(this.form.FactCost.element, false);
                    Serenity.EditorUtils.setReadonly(this.form.DateCost.element, false);
                    Serenity.EditorUtils.setReadonly(this.form.Notes.element, false);

                } 


            }
        }

All 6 comments

thanks, but this will make the control readonly all the time.
I use this code this.form.FromDtm.set_readOnly(true); in afterLoadEntity(), but I'm asking, if we can set the form to readonly according to a certain field value without use this code for every control in the form.

@amrgDev You can use a lookup and use se setectchange event

checkout the ReadOnly dialog example in the Serenity demo. simple variation to line 41 & 44 should get you the result.
https://github.com/volkanceylan/Serene/blob/master/Serene/Serene.Web/Modules/BasicSamples/Dialogs/ReadOnlyDialog/ReadOnlyDialog.ts

export class PayDialog extends Serenity.EntityDialog<PayRow, any> {
       .........................

        protected updateInterface() {
            super.updateInterface();
            if (!this.isNew()) {
                if (this.entity.Fact) {
                    Serenity.EditorUtils.setReadonly(this.element.find('.editor'), true);
                    this.element.find('sup').hide();
                    this.deleteButton.hide();
                    Serenity.EditorUtils.setReadonly(this.form.FactCost.element, false);
                    Serenity.EditorUtils.setReadonly(this.form.DateCost.element, false);
                    Serenity.EditorUtils.setReadonly(this.form.Notes.element, false);

                } 


            }
        }

Thanks @Zahar661 ,this match my requirments

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Shraddha996 picture Shraddha996  路  3Comments

moostafaa picture moostafaa  路  3Comments

Akarsh03 picture Akarsh03  路  3Comments

ahsansolution picture ahsansolution  路  3Comments

JohnRanger picture JohnRanger  路  3Comments