Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle readonly flag for form fields and change form fields enabling (disabled="disabled", ng-disabled="form.readonly") #225

Closed
flashnot opened this issue Jan 19, 2015 · 3 comments

Comments

@flashnot
Copy link

Hello. Please, help.

I have in app.js:
$scope.schema = {
    ...
    "readonly":true
};
$scope.form = [
    "nick",
    "email",
    {
        "key": "message",
        "type": "textarea",
        "placeholder": "Problem description",
    },
    {
        "type": "submit",
        "style": "btn-info",
        "title": "OK"
    }
    ];
$scope.model = {};
and in index.html:
<form sf-schema="schema" sf-form="form" sf-model="model"
    <div class="row">
        <div class="col-md-6">
            <div sf-insert-field="['nick']"></div>
        </div>
        <div class="col-md-6">
            <div sf-insert-field="['email']"></div>
        </div>
    </div>
</form>


I need button which can toggle form fields state (enable/disable for editing). How to implement it? Thanks, for any help.

@davidlgj
Copy link
Contributor

Hi @flashnot

There are two ways:

  1. Hook in an onChange on the button (or checkbox?) and re-render the form by changing the schema, removing or adding the "readonly" attribute. Currently it's a simple $watch so either the form object or the schema needs to be a different object instance for it to trigger a re-render.
    You can use angular.copy to prepare two versions of the schema, one which is readonly and one which is not.

  2. ...or you can use the type conditional. Make two conditional with expressions that listen to the same value but one that triggers when its true and one that triggers when its false. So one of them is always visible. You can then set one of them to be disabled and one to not be disabled with the form option readonly.

I'm closing this issue since it's neither a bug nor and enhancement request. Try stackoverflow if you have more problems, tag it with angular-schema-form and we will see it :-)

@EtiAggarwal
Copy link

The second method of using two conditionals worked for me, but when I switched to alpha3 it stopped working. I am using the conditionals inside an array.

@Anthropic
Copy link
Member

@EtiAggarwal can you make an issue with a plunker?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants