BootsFaces-OSP: Inputs with col-XX generate invalid Bootstrap markup

With the following XHTML:

<b:inputText value="test" col-xs="6" label="Message" label-col-xs="6"/>

I’d expect it to generate something like:

<div class="form-group">
    <label for="message1" class="col-xs-6">Message</label>
    <div class="col-xs-6">
        <input type="text" class="form-control" id="message1"></input>
    </div>
</div>

But it’s generating the following instead:

<div id="j_idt6:j_idt7" class="form-group ">
    <label for="input_j_idt6:j_idt7" class=" col-xs-6 control-label">Message</label>
    <input id="input_j_idt6:j_idt7" name="input_j_idt6:j_idt7" class="form-control" value="test" type="text"></div>

You can see that only the label has col-xs-X defined.

If I only set the size for the input, like <b:inputText value="test" col-xs="6" label="Message" />, I get the following:

<div class="col-xs-6" id="j_idt6:j_idt7">
    <div class="form-group ">
        <label for="input_j_idt6:j_idt7" class=" control-label">Message</label>
        <input id="input_j_idt6:j_idt7" name="input_j_idt6:j_idt7" class="form-control" value="test" type="text">
    </div>
</div>

form-group acts like row for forms, so it doesn’t seem to be correct to wrap the row with a column. Also, the input size shouldn’t be ignored when setting the label width. This is needed in order to allow for more complex form designs (such as https://jsbin.com/jikiyuwuve/edit?html,output). Although more customization options will be needed for that. I’ll open an issue for that later.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hi,

You are right, he form class is effectively needed for added styles. But anyway, there are two problems with the markup not complaining with BS rules (at least to my understanding):

  • We are generating a column around a form-group. Since the form-group acts as a row, columns must be always inside it. This is needed for cases when two inputs are to be placed on the same line (while using col-xx). From what I see on the internet, that column would be a div wrapping the input.
  • When the label size is specified, only it has the col-xx attribute. That makes the input go full length without any option to place more inputs on the same row (form-group).

Yes, it’s a breaking change. But it depends on how you look at it. For me, if it generates wrong Bootstrap markup, that’s a priority to fix. And any behaviour depending on “wrong” markup can’t be taken for granted.

If not breaking BC in this cases is really a concern, I’d propose to use a context param to revert to the original markup. But that’s also more maintenance work…

A middleground aproach (given the times wr have) would be to add an option to inputs to just generate the input, without any added form-group markup, leaving the user the option to customize as needed.

But, for that case, I was going to propose the addition of a new b:formGroup component that generates just the form group div and prevents its generation for inputs that were direct children.

In other words, inputs would check if their parent is a b:formGroup and in that case, they would not generate the form-group div. That would allow for multi input rows without custom html and just using BS styles.

Not sure however how hard could it be.

El jue., 6 de abril de 2017 20:30, Stephan Rauh notifications@github.com escribió:

The markup is wrong because you didn’t add <form horizontal="true">. (Or at least I hope so because it was so hard and painful to get it right 😃).

Have a look at http://www3.bootsfaces.net/Showcase/forms/horizontalForms.jsf for more details.

Should we emit an error message, or should we silently correct the html code the way you suggest? In that case, I’d like to postpone it to BootsFaces 1.2 because it’s a breaking change and because it’s very difficult to get it right. There are so many options (AJAX vs. non-AJAX, facets, horizontal forms, stacked forms, inline forms, and last not least input fields without the col-* attributes).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/TheCoder4eu/BootsFaces-OSP/issues/682#issuecomment-292266480, or mute the thread https://github.com/notifications/unsubscribe-auth/ACAucAj8TQmNdYmOtdKoLuqpbyhku4i6ks5rtS9VgaJpZM4M1w1Q .