bolt / boltforms

Bolt 3 Forms extension - Symfony interface and API for Bolt
http://bolt.cm
GNU General Public License v3.0
52 stars 56 forks source link

Set placeholder attribute on day, month, year fields #163

Open jamieburchell opened 7 years ago

jamieburchell commented 7 years ago

According to the Symphony docs, it's possible to pass an array to the placeholder attribute to set a placeholder on the day/month/year input fields of a date type:

Alternatively, you can use an array that configures different placeholder values for the year, month and day fields:

https://symfony.com/doc/current/reference/forms/types/date.html#placeholder

I cannot get this to work in Bolt Forms. Is it supported?

My syntax might be incorrect; I have tried:

placeholder:
   year: 'yyyy'
   month: 'mm '
   day: 'dd'

placeholder: { year: 'yyyy', month: 'mm', day: 'dd' } placeholder: [ year: 'yyyy', month: 'mm', day: 'dd' ]

rossriley commented 7 years ago

Yes, if you read those docs carefully it says that this only applies if you've set your widget to choice I've tested it with this setup:

        birthday:
            type: date
            options:
                required: true
                widget: choice
                format: 'dd/MM/yyyy'
                label: Enter your Date of Birth (dd/mm/yy)
                placeholder:
                    day: 22
                    month: 03
                    year: 91

And the placeholder is preselected. If you change the widget to text, then it doesn't look as though it is used.

Seems to be confirmed by this comment here by one of the symfony/forms maintainers: https://github.com/symfony/symfony/pull/14862#issuecomment-113468692

jamieburchell commented 7 years ago

To be clear, I'm not referring to the "single_text" widget (in that comment), but the "text" (three separate input fields for day, month, year). I have read and re-read that documentation and that comment; it's not super clear to me that it can't be used to set the HTML placeholder attribute of the input fields.

rossriley commented 7 years ago

yes, I've tried it on all and it only goes through on widget: choice if you use widget: single_text then you can set the placeholder on the attr array, if you set placeholder in attr on the widget: text something like this:

birthday:
            type: date
            options:
                required: true
                widget: text
                format: 'dd/MM/yyyy'
                label: Enter your Date of Birth (dd/mm/yy)
                attr:
                    placeholder: 22/03/91

Then bizarrely you get a placeholder on the containing div, but I can't see any way to get it on the individual elements.

jamieburchell commented 7 years ago

I noticed that oddness to! OK thanks for looking in to this and confirming.