YiiBooster icon indicating copy to clipboard operation
YiiBooster copied to clipboard

Support for HTML5 form types in htmlOptions

Open kazuo opened this issue 13 years ago • 11 comments

I'm unsure if I should request this on the Yii Booster project or the Yii Bootstrap project, but I'm currently using Yii Booster, so here goes :)

Can we have some sort of "type" override when passing in htmlOptions for forms? I wanted to support HTML5 input with new "type" values (see http://www.w3schools.com/html/html5_form_input_types.asp)

I noticed I couldn't set the actual "type" (default to text when using text field) despite trying to pass in array('type'=>'email'). It may seem a bit confusing since the primitive type is a text field, but I wanted to use define it as 'email' instead of 'text' so that, for example, when using the form under a mobile platform like iOS, it should display the appropriate keyboard. (Another example would be type="tel" for the telephone number keypad to come up).

Creating a new method for every type (again, an email really is just a text field), might be overkill. Instead, if a "type" is defined in htmlOptions, it can replace the value after it does the rest of its magic.

I can try to come up with an implementation this weekend. (I'm just now thinking about if the user doesn't set a type in htmlOptions, maybe we can even check the model to see if it's an email, telephone number, etc and auto-populate/replace it for the HTML5 equivalent)

kazuo avatar Oct 24 '12 02:10 kazuo

Good idea, the rendering of 'text' should look for HTML5 types. Moving this for new milestone.

tonydspaniard avatar Oct 24 '12 10:10 tonydspaniard

Moved to next milestone. I am thinking to refactor the way to display simple types by making use of a new helper: TbHtml, any ideas welcome

tonydspaniard avatar Nov 25 '12 10:11 tonydspaniard

No time... moved to next milestone 1.0.6. Apologies @kazuo

tonydspaniard avatar Dec 08 '12 07:12 tonydspaniard

No worries. Only now I got a chance to check out CHtml. Did you already being work on this? If not, I can take probably whip something up before the end of the weekend. It just looks like we really only need to override textField() and activeTextField() and just check if there's a valid HTML5 $htmlOptions['type'] option to check against.

Let me know :)

kazuo avatar Dec 08 '12 20:12 kazuo

One of the things that I am thinking is to provide a TbHtml and get rid of the heavy use of widgets for simple UI components. Maybe is worth brainstorm a bit about how to do that..

Cheers

tonydspaniard avatar Dec 08 '12 21:12 tonydspaniard

Yeah, let's discuss more about that. I don't quite picture your vision for the simple UI components. Is it a pretty significant overhaul?

Anyway, I had the HTML5 types on the brain before I had to leave for the day and figure I could do something really quick. It's incomplete, but I currently have widgets/input using TbHtml instead of CHtml.

https://github.com/kazuo/YiiBooster-contribute/commit/015e8bb176a690aef2d80d7a87c2c1aed8c88129

Did we want all of (not just the input widgets) to use the new proposed TbHtml?

kazuo avatar Dec 08 '12 21:12 kazuo

Thats not what I was actually thinking. I would like to avoid the use of widgets (input horizontal or input vertical) for simple UI elements ( text, textarea, checkboxes, radio, etc...) and instead the form to call the input horizontal or input vertical make use of smart TbHtml component that will allow TbActiveForm to make use directly instead of creating a widget for each one of them in TbInputHorizontal or TbInputVertical.

Still have to be B/C compatible.

tonydspaniard avatar Dec 09 '12 09:12 tonydspaniard

Ah, I see. So we'd pretty much break away from Yii Bootstrap with that kind of change, correct?

kazuo avatar Dec 13 '12 02:12 kazuo

Moved to 1.0.7 milestone. Only bugfixes will be in 1.0.6 from now on.

hijarian avatar Feb 12 '13 10:02 hijarian

TbInput[Inline|Horizontal|Vertical].php

         /**
         * Renders a text field.
         *
         * @return string the rendered content
         */
        protected function textField()
        {
            ....
            if (isset($this->htmlOptions['type']))
                $type = $this->htmlOptions['type'];
            else
                $type = 'text';
            $method = $type . "Field";
            echo $this->form->$method($this->model, $this->attribute, $this->htmlOptions);
            ...
        }

k102 avatar Oct 04 '13 15:10 k102

Is there now support for HTML 5 tags?

EvilKarter avatar Dec 10 '13 14:12 EvilKarter