boltforms icon indicating copy to clipboard operation
boltforms copied to clipboard

Set placeholder attribute on day, month, year fields

Open jamieburchell opened this issue 7 years ago • 4 comments

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' ]

jamieburchell avatar Jul 28 '17 21:07 jamieburchell

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

rossriley avatar Jul 28 '17 21:07 rossriley

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.

jamieburchell avatar Jul 28 '17 21:07 jamieburchell

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.

rossriley avatar Jul 28 '17 21:07 rossriley

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

jamieburchell avatar Jul 28 '17 22:07 jamieburchell