Skip to content

Global options does not propagate properly #121

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

Open
davidlgj opened this issue Oct 14, 2014 · 12 comments
Open

Global options does not propagate properly #121

davidlgj opened this issue Oct 14, 2014 · 12 comments
Milestone

Comments

@davidlgj
Copy link
Contributor

See #29 (comment)

@nertus
Copy link

nertus commented Mar 2, 2015

Any fix?

@davidlgj
Copy link
Contributor Author

davidlgj commented Mar 2, 2015

Nope not yet.

mån 2 mars 2015 kl 12:16 skrev Aliaksandr Pshanichnik <
[email protected]>:

Any fix?


Reply to this email directly or view it on GitHub
#121 (comment)
.

@golfmat1
Copy link
Contributor

Would I be correct in assuming that this affects all global options, in particular readonly? E.g. I'm having trouble getting the following to work, i.e. the entire form is still editable:

<div sf-model="..." sf-form="..." sf-schema="..." sf-options="{ formDefaults: { readonly: true } }"></div>

@golfmat1
Copy link
Contributor

Created small pull request (#396) that fixes my issue for the initial form rendering.

However, if the model/schema is changed, any updates to the global options aren't realized in the newly rendered form: e.g. if I display one model as readonly then try to show another in the same form as not readonly, it will still not be editable.

@davidlgj
Copy link
Contributor Author

@golfmat1 is that after a schemaFormRedraw event?

@golfmat1
Copy link
Contributor

I'm not sure. I tried to broadcast that event and still had the issue

However, I'm relatively new to angular and working within a framework in which there are numerous things I could be doing wrong. So it's perfectly possible that I wasn't triggering it correctly.

I created a workaround for now using schemaFormProvider.postProcess to explicitly set readonly on all form elements. This works, though it is probably not ideal.

@davidlgj
Copy link
Contributor Author

@golfmat1 I'm asking since you need to either change the entire form (or schema) instance, otherwise you need the event, and its easy to forget :)

@plong0
Copy link

plong0 commented Jun 26, 2015

any update on this one?

having the same problem described in other threads, formDefaults validationMessage applied to top-level items, but not into sub-sections

@jmaister
Copy link

I am having the same problem here.

I try to toggle the form between read-only and edit but it does not update the form state.

$scope.basic.options = { formDefaults: { readonly: true } };
$scope.toggleEdit = function() {
    $scope.basic.options.formDefaults.readonly = !$scope.basic.options.formDefaults.readonly;
};

@cmartin81
Copy link

Any update on this issue?

@doingweb
Copy link

@cmartin81 #396 was merged and released in v0.8.3. I can confirm that fix solved the issue for me (trying to set allowInvalid). @plong0 @jmaister - are you still seeing the same issue after upgrading?

stanimoto pushed a commit to stanimoto/angular-schema-form that referenced this issue Feb 25, 2016
The problem was that initialForm was used to generate a form on redraw
event, but when it was an object type, it was modified in-place by
rendering function. So, when the next redraw event happened, initialForm
already had the properties defined, and it prevented the default values
from being populated into them.
@stanimoto
Copy link

I am having the same issue as @jmaister , and I am able to reproduce with the latest version (v0.8.12) as of now. Here's a minimal code. It works on the first click, but it fails after that.

PR is here #644 .

<!doctype html>
<html>
<head>
<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
<script type="text/javascript" src="bower_components/angular-sanitize/angular-sanitize.min.js"></script>
<script type="text/javascript" src="bower_components/tv4/tv4.js"></script>
<script type="text/javascript" src="bower_components/objectpath/lib/ObjectPath.js"></script>
<script type="text/javascript" src="bower_components/angular-schema-form/dist/schema-form.js"></script>
<script type="text/javascript" src="bower_components/angular-schema-form/dist/bootstrap-decorator.js"></script>
<script type="text/javascript">
var app = angular.module('myModule', ['schemaForm']);

app.controller('FormController', function($scope) {

    $scope.schema = {
        "type": "object",
        "properties": {
            "foo": { type: "string" }
        }
    };
    $scope.form = [
        { key: "foo" }
    ];

    $scope.sfOptions = { formDefaults: {} };

    $scope.toggle = function () {
        $scope.sfOptions.formDefaults.readonly = !$scope.sfOptions.formDefaults.readonly;
        $scope.$broadcast('schemaFormRedraw');
    };
});
</script>
</head>
<body ng-app="myModule">

<div ng-controller="FormController">
    <form>
        <div sf-schema="schema" sf-form="form" sf-options="sfOptions"></div>
        <button ng-click="toggle()">Toggle</button>
    </form>
</div>

</body>
</html>

stanimoto pushed a commit to stanimoto/angular-schema-form that referenced this issue Feb 25, 2016
The problem was that initialForm was used to generate a form on redraw
event, but when it was an object type, it was modified in-place by
rendering function. So, when the next redraw event happened, initialForm
already had the properties defined, and it prevented the default values
from being populated into them.
stanimoto pushed a commit to stanimoto/angular-schema-form that referenced this issue Mar 3, 2016
The problem was that initialForm was used to generate a form on redraw
event, but when it was an object type, it was modified in-place by
rendering function. So, when the next redraw event happened, initialForm
already had the properties defined, and it prevented the default values
from being populated into them.
Anthropic added a commit that referenced this issue Mar 9, 2016
Fix for #121 to redraw with proper defaults
@Anthropic Anthropic modified the milestone: Backlog Apr 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants