Friday, 15 February 2013

Set readOnly for all form fields Using the Extjs 4.1 MVC.

Hi !

I'm doing my first extj mvc app, so I can't talk about best practice...

In my app I try to Set readOnly for all form fields.

Controller function :

init: function() {
            '#ViewId': { click: this.onView }
onView: function(button) {

    button.up('form').query('.field').forEach(function(field) {
            if (field.inputEl) {
                field.inputEl.dom.setAttribute('readOnly', true);
            } else {
                field.readOnly = true;

on Button click Event of my button is  onView, in that i am findingOut the form and inthat and all fields.
on loop through am setting the readOnly to the fields.
Instead of using Read Only use disable based on your Requirements

Note: This Only sets the Element's rearOnly DOM attribute. while Setting readOnly = true,
but in Extjs 4.1/ MVC we cant hide the triggering a combo Box or Date (Extjs 4.1.1 Release Notes).To hide the trigger use hide Trigger.

1 comment:

  1. button.up('form').getForm().getFields().each (function (field) {
    field.setReadOnly (true);