fields icon indicating copy to clipboard operation
fields copied to clipboard

prefix attribute is ignored

Open ghost opened this issue 11 years ago • 7 comments

Maybe I'm misunderstanding something, but when the following field is rendered

<f:field property="name" label="Name" prefix="foo.">
        <g:textField name="${property}" value="${value}" class="input-xlarge" maxlength="191"/>
</f:field>

The name of the input is "name", shouldn't it be "foo.name"?

ghost avatar Sep 12 '14 23:09 ghost

That's the idea, yeah. Looks like a bug. Is it only when you use a body like that?

robfletcher avatar Sep 13 '14 09:09 robfletcher

No, the prefix is also ignored even when there's no body, e.g.

<f:field bean="beanInstance" property="name" label="Name" prefix="foo."/>

ghost avatar Sep 13 '14 10:09 ghost

Just ran into your first problem myself. You might just need to specify the prefix explicitly in the body:

<f:field property="name" label="Name" prefix="foo.">
        <g:textField name="${prefix}${property}" value="${value}" class="input-xlarge" maxlength="191"/>
</f:field>

That's mentioned under Customized Field Rendering (https://grails-fields-plugin.github.io/grails-fields/guide/single.html#customizingFieldRendering) in the docs--see the "Template Parameters" section.

Not sure about the second issue, though, or if they're related, in your case.

tsweetser avatar Oct 16 '14 18:10 tsweetser

Just like tsweetser mentions, the docs do say that including the prefix in a custom template is a manual proces: prefix: "A string (including the trailing period) that should be appended before the input name such as name="${prefix}propertyName". The label is also modified."

I've just made a demo project, Grails 2.4.3, and it works fine, including the prefix.

@domurtag: Are you sure you don't have a custom template like: grails-app/views/_fields/default/_field.gsp That does not include the prefix variable?

I cannot reproduce this problem.

JacobAae avatar Oct 24 '14 20:10 JacobAae

If the documentation is wrong, please make a pull request on that too. Thanks!

sbglasius avatar Oct 24 '14 20:10 sbglasius

sbglasius: I think the documentation (and behavior of the plugin) is correct. It makes sence that you have both the prefix and the propertyName available, and not by default concatenated.

JacobAae avatar Oct 24 '14 20:10 JacobAae

@JacobAae You're right my _field.gsp template looks like this:

<div class="fieldColumn">
    <%=widget%>
</div>

So it seems that as things currently stand I need to specify a body if I want to use a prefix, e.g.

<f:field property="name" prefix="foo.">
    <g:textField name="${prefix}${property}" value="${value}" />
</f:field>

Obviously it would be preferable if I could do this instead

<f:field property="name" prefix="foo."/>

But if the docs say that I need to provide a body, then I guess I'm proposing an improvement rather than reporting a bug. I've changed the labels to reflect this.

ghost avatar Oct 24 '14 21:10 ghost