Support for HTML5 form types in htmlOptions
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)
Good idea, the rendering of 'text' should look for HTML5 types. Moving this for new milestone.
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
No time... moved to next milestone 1.0.6. Apologies @kazuo
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 :)
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
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?
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.
Ah, I see. So we'd pretty much break away from Yii Bootstrap with that kind of change, correct?
Moved to 1.0.7 milestone. Only bugfixes will be in 1.0.6 from now on.
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);
...
}
Is there now support for HTML 5 tags?