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

[RFR] Add the ability to set field template with label #772

Merged
merged 2 commits into from
Nov 12, 2015

Conversation

fzaninotto
Copy link
Member

In showView, editionView, and creationView, the template zone covers only the field itself - not the label. To force the template to replace the entire line (including the label), pass true as second argument to the template() call. This can be very useful to conditionally hide a field according to a property of the entry:

post.editionView()
    .fields([
        nga.field('category', 'choice')
            .choices([
                { label: 'Tech', value: 'tech' },
                { label: 'Lifestyle', value: 'lifestyle' }
            ]),
        nga.field('subcategory', 'choice')
            .choices(function(entry) {
                return subCategories.filter(function (c) {
                    return c.category === entry.values.category;
                });
            })
            // display subcategory only if there is a category
            .template('<ma-field ng-if="entry.values.category" field="::field" value="entry.values[field.name()]" entry="entry" entity="::entity" form="formController.form" datastore="::formController.dataStore"></ma-field>', true),
    ]);

Closes #755, #764

jeromemacias added a commit that referenced this pull request Nov 12, 2015
[RFR] Add the ability to set field template with label
@jeromemacias jeromemacias merged commit 12aa973 into master Nov 12, 2015
@jeromemacias jeromemacias deleted the template_with_label branch November 12, 2015 14:25
@jamespsterling
Copy link

When I try the example above, I get an infinite loop. Any idea what's causing this? I'm seeing the same behavior for all fields I try this on.

    submissions.editionView().fields([
        nga.field('submittedById', 'reference')
            .label('Submitted By')
            .targetEntity(user)
            .targetField(nga.field('name'))
            .editable(false)
            .template('<ma-field ng-if="entry.values.submittedById" field="::field" value="entry.values[field.name()]" entry="entry" entity="::entity" form="formController.form" datastore="::formController.dataStore">', true),

Error:

TypeError: Cannot read property 'submittedById' of undefined
    at p.n.getInputForField (ng-admin.min.js:15)
    at p.n.fieldHasValidation (ng-admin.min.js:15)
    at p.n.getFieldValidationClass (ng-admin.min.js:15)
    at Object.get (ng-admin.min.js:25)
    at p.$digest (ng-admin.min.js:24)
    at ng-admin.min.js:24
    at o (ng-admin.min.js:22)
    at ng-admin.min.js:22

@psorowka
Copy link

@jamespsterling did you resolve this infinite loop? I am observing the same behavior.

@ajarbol
Copy link

ajarbol commented Feb 11, 2016

@psorowka the digest loop is triggered when this is used with embedded_list targetFields...

@psorowka
Copy link

@ajarbol thanks for your comment! However, I just realized that my problems seem to result in the fact, that this feature hasn't actually been released to npm yet :) In the current release (0.9.1), the second parameter on template() is not handled and when applying an <ma-field> tag then, the loop is caused.

@fzaninotto this feature is already described in the docs but not yet available in the release. Do you plan to include it in an upcoming release?

@fzaninotto
Copy link
Member Author

Yes it will be in the next release, with no release date yet.

@psorowka
Copy link

thanks. so at least this is now documented allowing others to avoid this struggle :)

@jamespsterling
Copy link

Is this still unreleased? Adding true as the 2nd argument to template method does nothing.

@fzaninotto
Copy link
Member Author

You need to use version 1.0.0-alpha4 (which is not labeled stable) to test it.

@jamespsterling
Copy link

@fzaninotto great, I'll give it a shot! Any idea when 1.0.0 will be released?

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

Successfully merging this pull request may close these issues.

5 participants