Apollo
Apollo

Reputation: 9064

Making jquery mobile textfield on same line as text

Is there a way to do the following with jQuery Mobile?

Hello [________________________]

instead of what jQuery Mobile currently does, which is put these two on multiple lines:

Hello

[________________________]

Currently I am creating my text and textinput like so:

<div id="customTagEntryDiv">
  <span id="userTag">Hello</span>
  <input type="text" name="customTagField" id="customTagField" value=""  />
  </div> 

Upvotes: 5

Views: 15559

Answers (3)

HerrimanCoder
HerrimanCoder

Reputation: 7226

This no longer works:

<div data-role="fieldcontain"></div>

An old-fashioned table works great:

<table>
    <tr>
        <td>Label #1:</td>
        <td><input type="text"></td>
    </tr>
</table>

Upvotes: 0

den232
den232

Reputation: 730

float:left will do the trick. See this example with lines of normal and mini-sized fields:

http://jsfiddle.net/den232/WzH3Y/

    .floatleft {
    float:left;
 }
.floatright {
    float:right;
 }
.forceinline{  /* Prevent fieldcontain from doing a BLOCK thing */
    display:inline !important;
}
.textwidth {  /* limit width of input fields */
    width:80px;
}
.closespacing { /* controls spacing between elements */
    margin:0px 5px 0px 0px;
 }
.bigselect {   /* centers select with big buttons */
    padding: 0px;
    margin:2px 5px 0px 0px;
 }
.biginputheight {   /* matches text input height to big buttons */
    padding-top:10px !important;
    padding-bottom:12px !important;
}
.miniinputheight { /* matches text input height to minibuttons */
    padding-top:5px !important;
    padding-bottom:5px !important;
}
<div data-role="page" class="type-home">

<ul data-role="listview">
  <li  data-role="fieldcontain">first LI line</li>
  <li  data-role="fieldcontain">

    <div class='floatleft closespacing'>
        Big Buttons<br>More Text
    </div>


    <div  class='floatleft textwidth'>
      <input type="text" placeholder="left" class='biginputheight'></input>
    </div>  

    <div  class='floatright textwidth'>
      <input type="text" placeholder="right" class='biginputheight'></input>
    </div>  

  </li>
  <li  data-role="fieldcontain">

    <div class='floatleft closespacing'>    
        Small Buttons
    </div>


    <div  class='floatleft textwidth'>
      <input type="text" placeholder="e2" class='miniinputheight'></input>
    </div>  


    <div class='floatright closespacing'>
      <div  class='floatright closespacing'>    
        e3 Text<br>on right
      </div>
      <div  class='floatright textwidth'>
        <input type="text" placeholder="e3" class='miniinputheight'></input>
      </div>  
    </div>
  </li>
  <li  data-role="fieldcontain">last LI line</li>

</ul><!-- /listview -->  

Upvotes: 0

Littm
Littm

Reputation: 4947

Yes you can, you need to use field containers, with data-role="fieldcontain".

For example:

<div data-role="fieldcontain">
    <label for="name">Text Input:</label>
    <input type="text" name="name" id="name" value=""  />
</div>  

With the code above, you should get something like this:

Text Input: [____________]

and not something like this:

Text Input:
[____________]

You can use this "format" for many types of elements: text inputs, radio buttons, select menus, etc. However, I think that if your text is too long, in this case, the element may automatically go to the next line...


Given your example, you may wanna try something like this:

<div id="customTagEntryDiv" data-role="fieldcontain">
    <label id="userTag" for="customTagField">Hello</label>
    <input type="text" name="customTagField" id="customTagField" value=""  />
</div> 

Check the online doc for more information: http://jquerymobile.com/demos/1.1.1/docs/forms/textinputs/

Hope this helps.

Upvotes: 18

Related Questions