jQuery Mobile forms combining input elements

116 views Asked by At

When using jQuery mobile, is it possible to combine a checkbox or button with a text input? Something like in my image below.

I want to use it as field validation so it will turn red or green when user updates the field.

enter image description here

1

There are 1 answers

0
ezanker On

jQuery Mobile does not include this, but you can do it via CSS.

Here is a DEMO with a couple of options

The first uses a table, so the left button is always the same size and the input grows/shrinks on window resize. While the second option uses a div and bothe button and label grow shrink.

Fot the table, the css removes borders and spacing on the table and sets the first td width to a constant value. The rest of the css makes the button and input look right:

<table id="specialContTbl">
  <tr>
    <td class="btntd">
      <button data-role="none" id="btn">B</button>
    </td>
    <td class="inptd">
      <input data-role="none" type="text" id="inp1" name="inp1" value="" placeholder="enter some text" />
    </td>
  </tr>
</table>

#specialContTbl {
    border-spacing: 0;
    border-collapse: collapsed;
}
#specialContTbl td {
    padding:0;
    margin: 0;
    border: 0;
    vertical-align: top;
}
#specialContTbl td:first-child{
    width: 60px;
}
#specialContTbl{
    width: 100%;
}
#specialContTbl button, #specialContTbl input {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
#specialContTbl button {
    font-weight: normal;
    background: #00f050;
    padding: 5px;
    color: #333;
    border: 1px solid #d4d4d4;
    border-right: 0;
    border-bottom-left-radius:1em;
    border-top-left-radius: 1em;    
    line-height: 28px;
    height: 38px;
    width: 100%;
    float: left;
    text-align: center;
    cursor: pointer;
    white-space:nowrap;
}
#specialContTbl input {
    width: 100%;
    height: 38px;
    padding: 8px;
    border: 1px solid #d4d4d4;
    border-bottom-right-radius: 1em;
    border-top-right-radius: 1em;
    line-height: 18px;
    float: right;
    box-shadow: inset 0px 2px 2px #ececec;
}
#specialContTbl input:focus {
    outline: 0;
}