deepThought
deepThought

Reputation: 699

angular formly read-only mode for radio , multiCheckbox and checkbox

I need to display the form in read-only mode , I am creating the form based on Json using angular-formly . Checked the link http://angular-formly.com/#/example/other/read-only-form which works for text input , please suggest how to set read-only for radio , multicheckbox and checkbox

Upvotes: 4

Views: 1840

Answers (1)

MattE
MattE

Reputation: 1114

we do it via jQuery:

   $(document).ready(function () {
            $('input').click(function (e) {
                e.preventDefault();
            });
        });

OR if you want to "pretend" you are using "angular" to do this, even though you are actually using jQuery, and want to type out a whole lot more code to write the exact same thing(literally, it will simply run the above code in jQuery as angular.element is an "alias" for jQuery---straight out of the angular docs: https://docs.angularjs.org/api/ng/function/angular.element), you can do:

   angular.element(function() {
        angular.element('input').trigger('click')(function(e) {
            e.preventDefault();
        };
   });

This way you can look cool and spout off nonsense like "It's bad practice to run angular and jQuery together" because you have no clue what you are talking about and just read that somewhere.

This works for all input fields. If you have buttons or datepickers with buttons, etc the easiest way to do it is to set a readOnly property on the model in the form and then set it to true on page where you want it to be read only then set the ng-show on the buttons to: ng-show="!model.readOnly"

Upvotes: 1

Related Questions