Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
152
rated 0 times [  156] [ 4]  / answers: 1 / hits: 11568  / 11 Years ago, thu, january 16, 2014, 12:00:00

I have a bootstrap v3 inline form:



<div id=searchsection hidden>
<form id=searchform class=form-inline role=form>
<label>Find:</label>
<select id=field class=form-control>
<optgroup label=Strings>
<option value=authors selected=selected>Authors</option>
<option value=title>Title</option>
<option value=pub>Publication Name</option>
<option value=keywords>Keywords</option>
<option value=physloc>Physical Location</option>
<option value=comment>Comment</option>
</optgroup>
<optgroup label=Dates>
<option value=datepub>Publication Date</option>
<option value=dateread>Date Read</option>
</optgroup>
</select>

<input type=text id=narrowon1 class=form-control/>
<label for=narrowon2 class=form-control></label>
<input type=text id=narrowon2 class=form-control placeholder=YYYYMM hidden/>
<input type=button id=narrower name=narrower value=Narrow class=form-control btn btn-primary/>
<input type=button id=widener name=widener value=Widen class=form-control btn btn-primary/>
</form>
</div> <!-- end of searchsection -->


I would like to reduce the width of the boxes narrowon1 and narrowon2 when the optgroup is Dates so that they would only hold six digits each; I am thinking of setting size=6. However, when I simply add those attributes in jQuery via a statement such as



$('#narrowon1').attr('size',6);


they don't affect the rendered output. I expect the Bootstrap classes are overriding my additions.



What is a Bootstrap-friendly way to alter the sizes of these input boxes?


More From » html

 Answers
7

The maxlength attribute will not be affected by any CSS applied to the <input>. How are you applying it in javascript as you can't limit the character length with CSS?



I think you might be mistaking the maxlength attribute with the actual width of the <input>. Here is a some info on the attribute: Maxlength Attribute



View the log and make sure your <input> looks like this:



<input maxlength=6 name=someInput />


Edit:



Place a class of your own on the input and place new styles on the <input>. Make sure your local CSS file loads after the bootstrap CSS. Than you can easily override it.



If you can't create a new CSS file, try $('input').css('width', '200px'); with jQuery


[#48627] Wednesday, January 15, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jesseh

Total Points: 579
Total Questions: 98
Total Answers: 99

Location: Reunion
Member since Mon, Dec 28, 2020
4 Years ago
;