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

Custom form labels in field_for and form_for at Yancy::Plugin::Form #92

Closed
pavelsr opened this issue Apr 6, 2020 · 1 comment
Closed

Comments

@pavelsr
Copy link

pavelsr commented Apr 6, 2020

E.g. I have a field which has following sql definition

`reg_address` VARCHAR(511) NOT NULL,

I want that in form corresponding <label>...</label> will be Registration address ( name attribute untouched )

For now I have following output of Yancy::Plugin::Form::input_for

%= app->yancy->form->input_for( $schema, 'reg_address' );
<div class="form-group">
    <label for="field-passports-reg_address">reg_address *</label>
    <input class="form-control" type="text" required="1" id="field-passports-reg_address" name="reg_address">
</div>

yancy->form->input %args have no way to customize <label> tag value

Currently there is only enum_labels param used for just boolean fields that generate output like

<div class="btn-group yes-no">
    <label class="btn btn-xs btn-outline-success">
        <input type="radio" name="is_admin" value="1"> Yes
</label>
    <label class="btn btn-xs btn-outline-danger">
        <input type="radio" name="is_admin" value="0" selected="selected"> No
</label>
</div>

Is there any undocumented way to customize label for other input types ?

If no, do you think that suggested feature would be useful ? If yes, I can try to make a PR.

@preaction
Copy link
Owner

What you want should be possible already through the schema configuration:

use Mojolicious::Lite;
plugin Yancy => {
    backend => '...',
    read_schema => 1, # this will fill in the rest of the schema
    schema => {
        passports => {
            properties => {
                reg_address => {
                    title => 'Registration address',
                    description => 'Put a description here, it will appear',
               },
        },
    },
};

The form plugins try to use the same information from the schema that the editor uses. All of the configuration here should work in the form plugin, too (though some of the more advanced fields are not yet implemented).

Also, it looks like the field_for() helper does take a %opt hash, it's just not documented ☹️. I'll fix the documentation. The %opt hash takes the same keys as the schema (so, title and description).

preaction added a commit that referenced this issue Apr 7, 2020
    [Added]

    - Added the ability for any "route" configuration to be a string.
      These will automatically be made into routes for you. Thanks
      @pavelsr for the suggestion! [Github #90]
    - Added "yancy.auth.logout" helper and route so that any authed user
      can be cleared out from any auth plugin. Thanks @pavelsr for the
      suggestion! [Github #91]

    [Fixed]

    - Fixed a bunch of missing/broken documentation (found by @pavelsr
      in #90, #91, and #92)
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

2 participants