Making a field read-only in the view

Hi

Another basic question I'm afraid...

I'm trying to force an int field to read only (dependent upon various conditions). However, I'm not having any luck. Is there a way to either alter the vardef metadata in a view (custom edit view) - or by altering the model?

I've had various attempts such as:

                this.fields[testArrayIndex].action="disabled";

                this.fields[testArrayIndex].def.readonly=true;

                this.fields[testArrayIndex].fieldDefs.readonly = true;

 

where testArrayIndex is the index for the field in question. The above is what appears to be set when the main field metadata has readonly = true defined. However, as I want this to be conditional on the state of the app, I can't use the server metadata for this.

 

Thanks

Parents Reply
  • Hi, Steven
    Your code didn't work for you because Nomad actually prepares and uses displayFields property to hold field definitions that will be used to instantiate and render fields. You can find it documented in JSDoc

    So to make field readonly you can add following snippet in either initialize or onBeforeRender  methods of your view like so:

    onBeforeRender() {
        this.displayFields[1].readonly = true;
        this._super();

    Ofc, replace [1] with your actual logic
    Hope this helps! Eugene


Children