Source

Iifom

Imizekelo kunye nezikhokelo zokusetyenziswa kweendlela zokulawula iifom, iinketho zokubeka, kunye namacandelo angokwezifiso ekudaleni iintlobo ezininzi zeefom.

Isishwankathelo

Ulawulo lwefom ye-Bootstrap yandisa kwizimbo zethu zefom eQaliswe ngokutsha ngeeklasi. Sebenzisa ezi klasi ukungena kwiziboniso zazo ezilungiselelwe unikezelo olungaguquguqukiyo kuzo zonke iibhrawuza kunye nezixhobo.

Qinisekisa ukusebenzisa uphawu olufanelekileyo typekuwo onke amagalelo (umzekelo, emailidilesi ye-imeyile okanye numberngolwazi lwamanani) ukuthatha ithuba lolawulo lwamagalelo amatsha njengesiqinisekiso se-imeyile, ukukhetha amanani, nokunye.

Nanku umzekelo okhawulezayo ukubonisa izimbo zeBootstrap. Gcina ufundela amaxwebhu kwiiklasi ezifunekayo, uyilo lwefom, kunye nokunye.

Soze sabelane nge-imeyile yakho nomnye umntu.
<form>
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
    <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
  </div>
  <div class="form-group form-check">
    <input type="checkbox" class="form-check-input" id="exampleCheck1">
    <label class="form-check-label" for="exampleCheck1">Check me out</label>
  </div>
  <button type="submit" class="btn btn-primary">Submit</button>
</form>

Ulawulo lwefom

Ulawulo lweefom zombhalo-njengo- <input>s, <select>s, kunye no <textarea>-s-zibhalwa kunye .form-controlneklasi. Okubandakanyiweyo zizitayile zenkangeleko jikelele, imeko ekugxilwe kuyo, ubungakanani, kunye nokunye.

Qiniseka ukuba uphonononga iifom zethu zesiko ukuqhubela phambili isimbo <select>s.

<form>
  <div class="form-group">
    <label for="exampleFormControlInput1">Email address</label>
    <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="[email protected]">
  </div>
  <div class="form-group">
    <label for="exampleFormControlSelect1">Example select</label>
    <select class="form-control" id="exampleFormControlSelect1">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
  <div class="form-group">
    <label for="exampleFormControlSelect2">Example multiple select</label>
    <select multiple class="form-control" id="exampleFormControlSelect2">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
  <div class="form-group">
    <label for="exampleFormControlTextarea1">Example textarea</label>
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
  </div>
</form>

Kumagalelo efayile, tshintshela .form-controlkwi .form-control-file.

<form>
  <div class="form-group">
    <label for="exampleFormControlFile1">Example file input</label>
    <input type="file" class="form-control-file" id="exampleFormControlFile1">
  </div>
</form>

Ubungakanani

Seta ubude usebenzisa iiklasi ezifana .form-control-lgkunye .form-control-sm.

<input class="form-control form-control-lg" type="text" placeholder=".form-control-lg">
<input class="form-control" type="text" placeholder="Default input">
<input class="form-control form-control-sm" type="text" placeholder=".form-control-sm">
<select class="form-control form-control-lg">
  <option>Large select</option>
</select>
<select class="form-control">
  <option>Default select</option>
</select>
<select class="form-control form-control-sm">
  <option>Small select</option>
</select>

Funda uqhubeleke

Yongeza readonlyuphawu lwe boolean kwigalelo ukunqanda ukulungiswa kwexabiso legalelo. Amagalelo okufunda kuphela abonakala ekhaphukhaphu (njengamagalelo avaliweyo), kodwa gcina ikhesa esemgangathweni.

<input class="form-control" type="text" placeholder="Readonly input here…" readonly>

Funda kuphela isicatshulwa esicacileyo

Ukuba ufuna ukuba <input readonly>nezinto kwimo yakho ezibhalwe njengombhalo ongenanto, sebenzisa .form-control-plaintextiklasi ukususa isimbo sommandla wefomu engagqibekanga kwaye ugcine umda ochanekileyo kunye nokhupho.

<form>
  <div class="form-group row">
    <label for="staticEmail" class="col-sm-2 col-form-label">Email</label>
    <div class="col-sm-10">
      <input type="text" readonly class="form-control-plaintext" id="staticEmail" value="[email protected]">
    </div>
  </div>
  <div class="form-group row">
    <label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword" placeholder="Password">
    </div>
  </div>
</form>
<form class="form-inline">
  <div class="form-group mb-2">
    <label for="staticEmail2" class="sr-only">Email</label>
    <input type="text" readonly class="form-control-plaintext" id="staticEmail2" value="[email protected]">
  </div>
  <div class="form-group mx-sm-3 mb-2">
    <label for="inputPassword2" class="sr-only">Password</label>
    <input type="password" class="form-control" id="inputPassword2" placeholder="Password">
  </div>
  <button type="submit" class="btn btn-primary mb-2">Confirm identity</button>
</form>

Uluhlu lweeNgeniso

Cwangcisa amagalelo oluhlu olusongelo oluthe tye usebenzisa .form-control-range.

<form>
  <div class="form-group">
    <label for="formControlRange">Example Range input</label>
    <input type="range" class="form-control-range" id="formControlRange">
  </div>
</form>

Iibhokisi zokutshekisha kunye noonomathotholo

Iibhokisi zokukhangela ezihlala zikhona kunye nonomathotholo ziphuculwe ngoncedo lwe .form-check, iklasi enye yazo zombini iindidi zegalelo eziphucula ubeko nokuziphatha kwezinto zabo ze HTML . Iibhokisi zokukhangela zezokukhetha enye okanye iinketho ezininzi kuluhlu, ngelixa oonomathotholo bezokukhetha ukhetho olunye kwabaninzi.

Iibhokisi zokukhangela ezikhubazekileyo kunye nonomathotholo ziyaxhaswa, kodwa ukubonelela not-allowedngekhesa kwihover yomzali <label>, kuya kufuneka udibanise disableduphawu kwi .form-check-input. Uphawu loyelelwano olukhubazekileyo luya kusebenzisa umbala olula ukunceda ukubonisa ubume begalelo.

Iibhokisi zokutshekisha kunye nosetyenziso lweerediyo zakhiwe ukuxhasa ukuqinisekiswa kwefomu esekwe kwi-HTML kunye nokubonelela ngeelebhile ezimfutshane, ezifikelelekayo. Ngaloo ndlela, <input>imiz kunye nemizalwane yethu <label>zizinto zokuzalana ngokuchaseneyo <input>nengaphakathi <label>. Oku kukwi-verbose kancinane njengoko kufuneka ukhankanye idkunye forneempawu zokunxulumana <input>ne <label>.

Okuhlala kukho (kupakishwe)

Ngokungagqibekanga, naliphi na inani leebhokisi zokukhangela kunye nonomathotholo abazalanayo baya kugcinwa ngokuthe nkqo kwaye zibekwe ngokufanelekileyo nge .form-check.

<div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="defaultCheck1">
  <label class="form-check-label" for="defaultCheck1">
    Default checkbox
  </label>
</div>
<div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="defaultCheck2" disabled>
  <label class="form-check-label" for="defaultCheck2">
    Disabled checkbox
  </label>
</div>
<div class="form-check">
  <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1" checked>
  <label class="form-check-label" for="exampleRadios1">
    Default radio
  </label>
</div>
<div class="form-check">
  <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
  <label class="form-check-label" for="exampleRadios2">
    Second default radio
  </label>
</div>
<div class="form-check">
  <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios3" value="option3" disabled>
  <label class="form-check-label" for="exampleRadios3">
    Disabled radio
  </label>
</div>

Nomgca

Qela iibhokisi zokukhangela okanye iirediyo kumqolo othe tye ngokudibanisa .form-check-inlinenakweyiphi .form-check.

<div class="form-check form-check-inline">
  <input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
  <label class="form-check-label" for="inlineCheckbox1">1</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2">
  <label class="form-check-label" for="inlineCheckbox2">2</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="checkbox" id="inlineCheckbox3" value="option3" disabled>
  <label class="form-check-label" for="inlineCheckbox3">3 (disabled)</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
  <label class="form-check-label" for="inlineRadio1">1</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">
  <label class="form-check-label" for="inlineRadio2">2</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" disabled>
  <label class="form-check-label" for="inlineRadio3">3 (disabled)</label>
</div>

Ngaphandle kweelebhile

Yongeza .position-statickumagalelo aphakathi .form-checkkoko akunambhalo weleyibhile. Khumbula ukuba usenokubonelela ngolunye uhlobo lweleyibhile yeetekhnoloji ezincedisayo (umzekelo, ukusebenzisa aria-label).

<div class="form-check">
  <input class="form-check-input position-static" type="checkbox" id="blankCheckbox" value="option1" aria-label="...">
</div>
<div class="form-check">
  <input class="form-check-input position-static" type="radio" name="blankRadio" id="blankRadio1" value="option1" aria-label="...">
</div>

Uyilo

Kuba iBootstrap isebenza display: blockkwaye width: 100%phantse kulo lonke uhlobo lwethu lolawulo, iifom ziya kuthi ngokungagqibekanga zipakishwe ngokuthe nkqo. Iiklasi ezongezelelweyo zingasetyenziselwa ukuhluka kolu yilo ngokwefom.

Yenza amaqela

Iklasi .form-groupyeyona ndlela ilula yokongeza isakhiwo kwiifom. Ibonelela ngodidi oluguquguqukayo olukhuthaza ukuhlelwa ngokufanelekileyo kweelebhile, ulawulo, isicatshulwa soncedo esikhethwayo, kunye nefomu yokuqinisekisa imiyalezo. Ngokungagqibekanga iyasebenza kuphela margin-bottom, kodwa ithatha izitayile ezongezelelweyo .form-inlinenjengoko kufuneka. Yisebenzise kunye no- <fieldset>s, <div>s, okanye phantse nayiphi na enye into.

<form>
  <div class="form-group">
    <label for="formGroupExampleInput">Example label</label>
    <input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
  </div>
  <div class="form-group">
    <label for="formGroupExampleInput2">Another label</label>
    <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
  </div>
</form>

Igridi yefom

Iifom ezinzima ngakumbi zinokukhiwa kusetyenziswa iiklasi zethu zegridi. Sebenzisa ezi kuyilo lweefom ezifuna iikholamu ezininzi, ububanzi obahlukeneyo, kunye nokhetho olongezelelweyo lolungelelwaniso.

<form>
  <div class="row">
    <div class="col">
      <input type="text" class="form-control" placeholder="First name">
    </div>
    <div class="col">
      <input type="text" class="form-control" placeholder="Last name">
    </div>
  </div>
</form>

Yenza umqolo

Ungatshintshiselana kwakhona .row, .form-rowumahluko womqolo wethu wegridi osemgangathweni ogqithisela ngaphezulu kwimijelo yoluhlu olumiselweyo loyilo oluqina kunye noluxineneyo ngakumbi.

<form>
  <div class="form-row">
    <div class="col">
      <input type="text" class="form-control" placeholder="First name">
    </div>
    <div class="col">
      <input type="text" class="form-control" placeholder="Last name">
    </div>
  </div>
</form>

Uyilo oluntsonkothileyo lunokwenziwa kunye nenkqubo yegridi.

<form>
  <div class="form-row">
    <div class="form-group col-md-6">
      <label for="inputEmail4">Email</label>
      <input type="email" class="form-control" id="inputEmail4" placeholder="Email">
    </div>
    <div class="form-group col-md-6">
      <label for="inputPassword4">Password</label>
      <input type="password" class="form-control" id="inputPassword4" placeholder="Password">
    </div>
  </div>
  <div class="form-group">
    <label for="inputAddress">Address</label>
    <input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
  </div>
  <div class="form-group">
    <label for="inputAddress2">Address 2</label>
    <input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
  </div>
  <div class="form-row">
    <div class="form-group col-md-6">
      <label for="inputCity">City</label>
      <input type="text" class="form-control" id="inputCity">
    </div>
    <div class="form-group col-md-4">
      <label for="inputState">State</label>
      <select id="inputState" class="form-control">
        <option selected>Choose...</option>
        <option>...</option>
      </select>
    </div>
    <div class="form-group col-md-2">
      <label for="inputZip">Zip</label>
      <input type="text" class="form-control" id="inputZip">
    </div>
  </div>
  <div class="form-group">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="gridCheck">
      <label class="form-check-label" for="gridCheck">
        Check me out
      </label>
    </div>
  </div>
  <button type="submit" class="btn btn-primary">Sign in</button>
</form>

Ifom ethe tye

Yenza iifom ezithe tyaba ngegridi ngokudibanisa .rowiklasi ukwenza amaqela kunye nokusebenzisa .col-*-*iiklasi ukucacisa ububanzi beelebhile zakho kunye nolawulo. Qinisekisa ukuba ukongeza .col-form-labelkwi- <label>s yakho ngokunjalo ukuze babekwe ngokuthe nkqo embindini nolawulo lwefom enxulumeneyo.

Ngamanye amaxesha, kuya kufuneka usebenzise i-margin okanye i-padding eziluncedo ukwenza ulungelelwaniso olugqibeleleyo oludingayo. Umzekelo, siyisusile padding-topileyibhile kwirediyo yethu epakishweyo ukuze silungelelanise ngcono isiseko sombhalo.

Oonomathotholo
Ibhokisi yokujonga
<form>
  <div class="form-group row">
    <label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
    </div>
  </div>
  <div class="form-group row">
    <label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
    </div>
  </div>
  <fieldset class="form-group">
    <div class="row">
      <legend class="col-form-label col-sm-2 pt-0">Radios</legend>
      <div class="col-sm-10">
        <div class="form-check">
          <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios1" value="option1" checked>
          <label class="form-check-label" for="gridRadios1">
            First radio
          </label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios2" value="option2">
          <label class="form-check-label" for="gridRadios2">
            Second radio
          </label>
        </div>
        <div class="form-check disabled">
          <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios3" value="option3" disabled>
          <label class="form-check-label" for="gridRadios3">
            Third disabled radio
          </label>
        </div>
      </div>
    </div>
  </fieldset>
  <div class="form-group row">
    <div class="col-sm-2">Checkbox</div>
    <div class="col-sm-10">
      <div class="form-check">
        <input class="form-check-input" type="checkbox" id="gridCheck1">
        <label class="form-check-label" for="gridCheck1">
          Example checkbox
        </label>
      </div>
    </div>
  </div>
  <div class="form-group row">
    <div class="col-sm-10">
      <button type="submit" class="btn btn-primary">Sign in</button>
    </div>
  </div>
</form>
Ubungakanani belebhile yefom ethe tye

Qinisekisa ukusebenzisa .col-form-label-smokanye .col-form-label-lgkwi- <label>s okanye <legend>kwi-s yakho ukulandela ngokuchanekileyo ubungakanani .form-control-lgkunye ne .form-control-sm.

<form>
  <div class="form-group row">
    <label for="colFormLabelSm" class="col-sm-2 col-form-label col-form-label-sm">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control form-control-sm" id="colFormLabelSm" placeholder="col-form-label-sm">
    </div>
  </div>
  <div class="form-group row">
    <label for="colFormLabel" class="col-sm-2 col-form-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="colFormLabel" placeholder="col-form-label">
    </div>
  </div>
  <div class="form-group row">
    <label for="colFormLabelLg" class="col-sm-2 col-form-label col-form-label-lg">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control form-control-lg" id="colFormLabelLg" placeholder="col-form-label-lg">
    </div>
  </div>
</form>

Ubungakanani bekholamu

Njengoko kubonisiwe kwimizekelo yangaphambili, inkqubo yethu yegridi ikuvumela ukuba ubeke naliphi na inani lika .cols ngaphakathi .rowokanye .form-row. Baza kwahlula ububanzi obukhoyo ngokulinganayo phakathi kwabo. Ungaphinda ukhethe iseti esezantsi yeentsika zakho ukuthatha indawo eninzi okanye encinci, ngelixa u- .cols oseleyo wahlulahlula ngokulinganayo okunye, ngeeklasi ezithile zekholamu njenge .col-7.

<form>
  <div class="form-row">
    <div class="col-7">
      <input type="text" class="form-control" placeholder="City">
    </div>
    <div class="col">
      <input type="text" class="form-control" placeholder="State">
    </div>
    <div class="col">
      <input type="text" class="form-control" placeholder="Zip">
    </div>
  </div>
</form>

Ukulinganisa okuzenzekelayo

Umzekelo ongezantsi usebenzisa into eluncedo ye-flexbox ukubeka embindini ngokuthe nkqo imixholo kunye notshintsho .colukuze .col-autoiikholomu zakho zithathe kuphela indawo eninzi njengoko kufuneka. Beka enye indlela, ubukhulu bekholamu ngokwayo ngokusekelwe kwimixholo.

@
<form>
  <div class="form-row align-items-center">
    <div class="col-auto">
      <label class="sr-only" for="inlineFormInput">Name</label>
      <input type="text" class="form-control mb-2" id="inlineFormInput" placeholder="Jane Doe">
    </div>
    <div class="col-auto">
      <label class="sr-only" for="inlineFormInputGroup">Username</label>
      <div class="input-group mb-2">
        <div class="input-group-prepend">
          <div class="input-group-text">@</div>
        </div>
        <input type="text" class="form-control" id="inlineFormInputGroup" placeholder="Username">
      </div>
    </div>
    <div class="col-auto">
      <div class="form-check mb-2">
        <input class="form-check-input" type="checkbox" id="autoSizingCheck">
        <label class="form-check-label" for="autoSizingCheck">
          Remember me
        </label>
      </div>
    </div>
    <div class="col-auto">
      <button type="submit" class="btn btn-primary mb-2">Submit</button>
    </div>
  </div>
</form>

Ungayixuba kwakhona loo nto kwakhona ngeeklasi zekholamu zobungakanani obuthile.

@
<form>
  <div class="form-row align-items-center">
    <div class="col-sm-3 my-1">
      <label class="sr-only" for="inlineFormInputName">Name</label>
      <input type="text" class="form-control" id="inlineFormInputName" placeholder="Jane Doe">
    </div>
    <div class="col-sm-3 my-1">
      <label class="sr-only" for="inlineFormInputGroupUsername">Username</label>
      <div class="input-group">
        <div class="input-group-prepend">
          <div class="input-group-text">@</div>
        </div>
        <input type="text" class="form-control" id="inlineFormInputGroupUsername" placeholder="Username">
      </div>
    </div>
    <div class="col-auto my-1">
      <div class="form-check">
        <input class="form-check-input" type="checkbox" id="autoSizingCheck2">
        <label class="form-check-label" for="autoSizingCheck2">
          Remember me
        </label>
      </div>
    </div>
    <div class="col-auto my-1">
      <button type="submit" class="btn btn-primary">Submit</button>
    </div>
  </div>
</form>

Kwaye ngokuqinisekileyo ulawulo lwefom yesiko luyaxhaswa.

<form>
  <div class="form-row align-items-center">
    <div class="col-auto my-1">
      <label class="mr-sm-2 sr-only" for="inlineFormCustomSelect">Preference</label>
      <select class="custom-select mr-sm-2" id="inlineFormCustomSelect">
        <option selected>Choose...</option>
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
      </select>
    </div>
    <div class="col-auto my-1">
      <div class="custom-control custom-checkbox mr-sm-2">
        <input type="checkbox" class="custom-control-input" id="customControlAutosizing">
        <label class="custom-control-label" for="customControlAutosizing">Remember my preference</label>
      </div>
    </div>
    <div class="col-auto my-1">
      <button type="submit" class="btn btn-primary">Submit</button>
    </div>
  </div>
</form>

Iifom zangaphakathi

Sebenzisa .form-inlineiklasi ukubonisa uluhlu lweelebhile, ulawulo lwefom, kunye namaqhosha kumqolo omnye othe tye. Ulawulo lweefomu ngaphakathi kweefom ezingaphakathi komgca ziyohluka kancinci kwiimeko zazo ezisilelayo.

  • Izilawuli zi display: flex, ziwisa nasiphi na isithuba esimhlophe seHTML kwaye ikuvumela ukuba unikeze ngolawulo lolungelelwaniso ngezithuba kunye nezinto eziluncedo ze - flexbox .
  • Amaqela olawulo kunye namagalelo afumana width: autoukukhuphela ngaphezulu i-Bootstrap engagqibekanga width: 100%.
  • Izilawuli zivela kuphela emgceni kwiizibuko zokujonga ubuncinane eziyi-576px ububanzi ukuze kunikwe ingxelo ngeendawo zokujonga ezimxinwa kwizixhobo eziphathwayo.

Kusenokufuneka ukuba ulungise ngesandla ububanzi kunye nolungelelwaniso lolawulo lwefomu nganye kunye nezixhobo zokubeka izithuba (njengoko kubonisiwe ngezantsi). Okokugqibela, qiniseka ukuba uhlala ubandakanya <label>ulawulo lwefom nganye, nokuba ufuna ukuyifihla kwiindwendwe ezingafundi isikrini nge .sr-only.

@
<form class="form-inline">
  <label class="sr-only" for="inlineFormInputName2">Name</label>
  <input type="text" class="form-control mb-2 mr-sm-2" id="inlineFormInputName2" placeholder="Jane Doe">

  <label class="sr-only" for="inlineFormInputGroupUsername2">Username</label>
  <div class="input-group mb-2 mr-sm-2">
    <div class="input-group-prepend">
      <div class="input-group-text">@</div>
    </div>
    <input type="text" class="form-control" id="inlineFormInputGroupUsername2" placeholder="Username">
  </div>

  <div class="form-check mb-2 mr-sm-2">
    <input class="form-check-input" type="checkbox" id="inlineFormCheck">
    <label class="form-check-label" for="inlineFormCheck">
      Remember me
    </label>
  </div>

  <button type="submit" class="btn btn-primary mb-2">Submit</button>
</form>

Ulawulo lwefom yesiko kunye nokukhetha kuyaxhaswa.

<form class="form-inline">
  <label class="my-1 mr-2" for="inlineFormCustomSelectPref">Preference</label>
  <select class="custom-select my-1 mr-sm-2" id="inlineFormCustomSelectPref">
    <option selected>Choose...</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>

  <div class="custom-control custom-checkbox my-1 mr-sm-2">
    <input type="checkbox" class="custom-control-input" id="customControlInline">
    <label class="custom-control-label" for="customControlInline">Remember my preference</label>
  </div>

  <button type="submit" class="btn btn-primary my-1">Submit</button>
</form>
Iindlela ezizezinye kwiilebhile ezifihliweyo

Itekhnoloji ezincedisayo ezifana nezifundi zesikrini ziya kuba nengxaki kwiifomu zakho ukuba awubandakanyi ileyibhile yalo lonke igalelo. Kwezi fom zangaphakathi, ungazifihla iilebhile usebenzisa .sr-onlyiklasi. Kukho ezinye iindlela ezizezinye zokubonelela ngeleyibhile yeetekhnoloji ezincedisayo, ezifana ne- aria-label, aria-labelledbyokanye titleuphawu. Ukuba akukho nanye kwezi ekhoyo, ubuchwephesha obuncedisayo busenokubhenela ekusebenziseni placeholderuphawu, ukuba lukhona, kodwa qaphela ukuba ukusetyenziswa placeholderkwendawo yezinye iindlela zokuleyibheli akucetyiswa.

Umbhalo woncedo

Isicatshulwa soncedo lwenqanaba lebhlokhi kwiifom zinokudalwa kusetyenziswa .form-text(eyaziwa ngaphambili njenge .help-block-v3). Okubhaliweyo koncedo lwangaphakathi kunokuphunyezwa ngokuguquguqukayo kusetyenziswa nasiphi na isiqalelo se-HTML esingaphakathi kunye neeklasi eziluncedo ezifana .text-muted.

Ukunxulumanisa isicatshulwa soncedo kunye nolawulo lwefom

Isicatshulwa soncedo kufuneka sidityaniswe ngokuthe gca nolawulo lwefom enxulumene nokusebenzisa aria-describedbyuphawu loyelelwano. Oku kuya kuqinisekisa ukuba iitekhnoloji ezincedisayo-ezifana nezifundi zesikrini-ziya kubhengeza lo mbhalo woncedo xa umsebenzisi egxile okanye engena kulawulo.

Umbhalo woncedo ongezantsi kongeniso ungalungiswa nge .form-text. Le klasi ibandakanya display: blockkwaye yongeza umda ophezulu wezithuba ezilula ukusuka kumagalelo angentla.

Iphasiwedi yakho mayibe nobude obuyi-8-20 oonobumba ubude, iqulathe oonobumba kunye namanani, kwaye mayingaqulathi izithuba, amagama akhethekileyo, okanye i-emoji.
<label for="inputPassword5">Password</label>
<input type="password" id="inputPassword5" class="form-control" aria-describedby="passwordHelpBlock">
<small id="passwordHelpBlock" class="form-text text-muted">
  Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
</small>

Okubhaliweyo okungaphakathi kunokusebenzisa nayiphi na into eqhelekileyo engaphakathi kwe HTML isiqalelo (inokuba yi <small>, <span>, okanye enye into) kungekho nto ingaphaya kodidi oluluncedo.

Kufuneka ibenamagama ayi-8-20 ubude.
<form class="form-inline">
  <div class="form-group">
    <label for="inputPassword6">Password</label>
    <input type="password" id="inputPassword6" class="form-control mx-sm-3" aria-describedby="passwordHelpInline">
    <small id="passwordHelpInline" class="text-muted">
      Must be 8-20 characters long.
    </small>
  </div>
</form>

Iifom ezikhubazekileyo

Yongeza disableduphawu lwe-boolean kwigalelo ukuthintela ukusebenzisana komsebenzisi kwaye ulwenze lubonakale lula.

<input class="form-control" id="disabledInput" type="text" placeholder="Disabled input here..." disabled>

Yongeza disableduphawu ku a <fieldset>ukuvala zonke izilawuli ngaphakathi.

<form>
  <fieldset disabled>
    <div class="form-group">
      <label for="disabledTextInput">Disabled input</label>
      <input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
    </div>
    <div class="form-group">
      <label for="disabledSelect">Disabled select menu</label>
      <select id="disabledSelect" class="form-control">
        <option>Disabled select</option>
      </select>
    </div>
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="disabledFieldsetCheck" disabled>
      <label class="form-check-label" for="disabledFieldsetCheck">
        Can't check this
      </label>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </fieldset>
</form>
Caveat ngeeankile

Ngokungagqibekanga, abakhangeli bazakuthatha lonke uhlobo lolawulo lwendalo ( <input>, <select>kunye <button>nezakhi) ngaphakathi <fieldset disabled>njengokukhubaziweyo, ukuthintela zombini ibhodi yezitshixo kunye nonxibelelwano lwemouse kuzo. Nangona kunjalo, ukuba ifom yakho ikwabandakanya <a ... class="btn btn-*">izinto, ezi ziya kunikwa kuphela isimbo se pointer-events: none. Njengoko kuphawuliwe kwicandelo malunga nemeko ekhubazekileyo yamaqhosha (kwaye ngokukodwa kwicandelo elingaphantsi lezinto ze-ankile), le propati ye-CSS ayikabekwa emgangathweni kwaye ayixhaswanga ngokupheleleyo kwi-Internet Explorer 10, kwaye ayizukuthintela abasebenzisi bebhodi yezitshixo ukuba ekwaziyo ukugxila okanye ukuvula la makhonkco. Ke ukuze ukhuseleke, sebenzisa iJavaScript yesiko ukuvala amakhonkco anjalo.

Ukuhambelana kwebrowser

Ngelixa i-Bootstrap izakusebenzisa ezi zimbo kuzo zonke iibhrawuza, i-Internet Explorer 11 nangaphantsi ayiluxhasi ngokupheleleyo disableduphawu lwe- <fieldset>. Sebenzisa iJavaScript yesiko ukuvala iseti yangaphandle kwezi bhrawuza.

Ukuqinisekiswa

Nikeza ngengxelo ebalulekileyo, esebenzayo kubasebenzisi bakho ngokuqinisekiswa kwefomu yeHTML5- ifumaneka kuzo zonke iibhrawuza zethu ezixhaswayo . Khetha kwingxelo yokuqinisekisa engagqibekanga yesikhangeli, okanye sebenzisa imiyalezo yesiko ngeeklasi ezakhelwe ngaphakathi kunye neJavaScript yokuqalisa.

Ngoku sicebisa ukuba kusetyenziswe izitayile zokuqinisekisa ngokwesiko, njengoko imiyalezo yokuqinisekisa isikhangeli semveli ayisoloko iboniswa kwiitekhnoloji ezincedisayo kuzo zonke izikhangeli (ingakumbi, iChrome kwidesktop nakwiselfowuni).

Ingaba isebenza kanjani

Nantsi indlela ukuqinisekiswa kwefomu kusebenza ngayo ngeBootstrap:

  • Uqinisekiso lwefom ye-HTML lusetyenziswa ngeeklasi ezimbini zobuxoki zeCSS, :invalidkunye :valid. Isebenza kwi <input>, <select>, kunye <textarea>neziqalelo.
  • I-Bootstrap imida :invalidkunye :validnezimbo .was-validatedkwiklasi yabazali, ihlala isetyenziswa kwi <form>. Kungenjalo, nayiphi na indawo efunekayo ngaphandle kwexabiso ibonisa njengengasebenziyo kumthwalo wephepha. Ngale ndlela, usenokukhetha ukuba zisebenze nini na (ngokwesiqhelo emva kokuba kuzanywa ukungenisa kwefomu).
  • Ukusetha kwakhona inkangeleko yefom (umzekelo, kwimeko yokungeniswa kwefomu eguquguqukayo usebenzisa i-AJAX), susa .was-validatediklasi ukusuka <form>kwakhona emva kokungeniswa.
  • Njengomba wokubuyela umva, .is-invalidkwaye .is-validiiklasi zinokusetyenziswa endaweni yeeklasi zobuxoki zoqinisekiso lwecala lomncedisi . Abafuni .was-validatedklasi yabazali.
  • Ngenxa yemiqobo kwindlela esebenza ngayo i-CSS, asinako (okwangoku) ukusebenzisa izitayile <label>kuleyo iza phambi kolawulo lwefom kwiDOM ngaphandle koncedo lweJavaScript yesiko.
  • Zonke iiphequluli zanamhlanje zixhasa umqobo wokuqinisekisa i-API , uthotho lweendlela zeJavaScript zokuqinisekisa ulawulo lwefom.
  • Imiyalezo yengxelo inokusebenzisa isikhangeli esingagqibekanga (eyahlukileyo kumkhangeli zincwadi ngamnye, kwaye ayinasitayile ngokusebenzisa iCSS) okanye izimbo zethu zengxelo eyongezelelweyo ngeHTML kunye neCSS.
  • Unokubonelela ngemiyalezo yokuqinisekisa ngokwesiko setCustomValiditykwiJavaScript.

Unaloo nto engqondweni, qwalasela ezi zidemo zilandelayo zeendlela zethu zokuqinisekisa ifom yesiko, iiklasi ezikhethiweyo zeseva, kunye nokungagqibekanga kwesikhangeli.

Izimbo zesiko

Kwimiyalezo yoqinisekiso lwendlela yeBootstrap yesiko, kuya kufuneka udibanise novalidateuphawu lwe boolean kweyakho <form>. Oku kuvala iingcebiso zesixhobo sengxelo yesikhangeli, kodwa isabonelela ngokufikelela kwifomu yoqinisekiso lweAPIs kwiJavaScript. Zama ukungenisa le fomu ingezantsi; yethu iJavaScript iya kuthintela iqhosha lokungenisa kwaye idlulisele ingxelo kuwe.

Xa uzama ukungenisa, uya kubona iindlela :invalidkunye :validnezimbo ezisetyenziswa kulawulo lwakho lwefom.

Looks good!
Looks good!
@
Please choose a username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.
You must agree before submitting.
<form class="needs-validation" novalidate>
  <div class="form-row">
    <div class="col-md-4 mb-3">
      <label for="validationCustom01">First name</label>
      <input type="text" class="form-control" id="validationCustom01" placeholder="First name" value="Mark" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationCustom02">Last name</label>
      <input type="text" class="form-control" id="validationCustom02" placeholder="Last name" value="Otto" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationCustomUsername">Username</label>
      <div class="input-group">
        <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroupPrepend">@</span>
        </div>
        <input type="text" class="form-control" id="validationCustomUsername" placeholder="Username" aria-describedby="inputGroupPrepend" required>
        <div class="invalid-feedback">
          Please choose a username.
        </div>
      </div>
    </div>
  </div>
  <div class="form-row">
    <div class="col-md-6 mb-3">
      <label for="validationCustom03">City</label>
      <input type="text" class="form-control" id="validationCustom03" placeholder="City" required>
      <div class="invalid-feedback">
        Please provide a valid city.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationCustom04">State</label>
      <input type="text" class="form-control" id="validationCustom04" placeholder="State" required>
      <div class="invalid-feedback">
        Please provide a valid state.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationCustom05">Zip</label>
      <input type="text" class="form-control" id="validationCustom05" placeholder="Zip" required>
      <div class="invalid-feedback">
        Please provide a valid zip.
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
      <label class="form-check-label" for="invalidCheck">
        Agree to terms and conditions
      </label>
      <div class="invalid-feedback">
        You must agree before submitting.
      </div>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>

<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
  'use strict';
  window.addEventListener('load', function() {
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    var forms = document.getElementsByClassName('needs-validation');
    // Loop over them and prevent submission
    var validation = Array.prototype.filter.call(forms, function(form) {
      form.addEventListener('submit', function(event) {
        if (form.checkValidity() === false) {
          event.preventDefault();
          event.stopPropagation();
        }
        form.classList.add('was-validated');
      }, false);
    });
  }, false);
})();
</script>

Ukungagqibeki kwesikhangeli

Awunamdla kwimiyalezo yengxelo yokuqinisekisa okanye ukubhala iJavaScript ukutshintsha indlela yokuziphatha? Konke kulungile, ungasebenzisa ukungagqibeki kwesikhangeli. Zama ukuthumela le fomu ingezantsi. Ngokuxhomekeke kwisikhangeli sakho kunye ne-OS, uya kubona indlela eyahlukileyo kancinane yengxelo.

Ngelixa ezi zimbo zempendulo zingenako ukwenziwa ngesitayile ngeCSS, usenokwenza ngokwesiko lombhalo wengxelo ngeJavaScript.

@
<form>
  <div class="form-row">
    <div class="col-md-4 mb-3">
      <label for="validationDefault01">First name</label>
      <input type="text" class="form-control" id="validationDefault01" placeholder="First name" value="Mark" required>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationDefault02">Last name</label>
      <input type="text" class="form-control" id="validationDefault02" placeholder="Last name" value="Otto" required>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationDefaultUsername">Username</label>
      <div class="input-group">
        <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroupPrepend2">@</span>
        </div>
        <input type="text" class="form-control" id="validationDefaultUsername" placeholder="Username" aria-describedby="inputGroupPrepend2" required>
      </div>
    </div>
  </div>
  <div class="form-row">
    <div class="col-md-6 mb-3">
      <label for="validationDefault03">City</label>
      <input type="text" class="form-control" id="validationDefault03" placeholder="City" required>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationDefault04">State</label>
      <input type="text" class="form-control" id="validationDefault04" placeholder="State" required>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationDefault05">Zip</label>
      <input type="text" class="form-control" id="validationDefault05" placeholder="Zip" required>
    </div>
  </div>
  <div class="form-group">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" value="" id="invalidCheck2" required>
      <label class="form-check-label" for="invalidCheck2">
        Agree to terms and conditions
      </label>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>

Icala lomncedisi

Sicebisa ukuba kusetyenziswe uqinisekiso lwecala lomxhasi, kodwa xa ufuna icala lomncedisi, ungabonisa iindawo ezingasebenziyo nezisebenzayo zefomu kunye .is-invalidne .is-valid. Qaphela ukuba .invalid-feedbackikwaxhaswa ngezi klasi.

Ibonakala intle!
Ibonakala intle!
@
Nceda khetha igama lomsebenzisi.
Nceda unikeze isixeko esisebenzayo.
Nceda unikeze imeko esebenzayo.
Nceda unikeze i-zip esebenzayo.
Kufuneka uvume phambi kokuba ungenise.
<form>
  <div class="form-row">
    <div class="col-md-4 mb-3">
      <label for="validationServer01">First name</label>
      <input type="text" class="form-control is-valid" id="validationServer01" placeholder="First name" value="Mark" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationServer02">Last name</label>
      <input type="text" class="form-control is-valid" id="validationServer02" placeholder="Last name" value="Otto" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationServerUsername">Username</label>
      <div class="input-group">
        <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroupPrepend3">@</span>
        </div>
        <input type="text" class="form-control is-invalid" id="validationServerUsername" placeholder="Username" aria-describedby="inputGroupPrepend3" required>
        <div class="invalid-feedback">
          Please choose a username.
        </div>
      </div>
    </div>
  </div>
  <div class="form-row">
    <div class="col-md-6 mb-3">
      <label for="validationServer03">City</label>
      <input type="text" class="form-control is-invalid" id="validationServer03" placeholder="City" required>
      <div class="invalid-feedback">
        Please provide a valid city.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationServer04">State</label>
      <input type="text" class="form-control is-invalid" id="validationServer04" placeholder="State" required>
      <div class="invalid-feedback">
        Please provide a valid state.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationServer05">Zip</label>
      <input type="text" class="form-control is-invalid" id="validationServer05" placeholder="Zip" required>
      <div class="invalid-feedback">
        Please provide a valid zip.
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="form-check">
      <input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheck3" required>
      <label class="form-check-label" for="invalidCheck3">
        Agree to terms and conditions
      </label>
      <div class="invalid-feedback">
        You must agree before submitting.
      </div>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>

Izinto ezixhaswayo

Iifomu zethu zemizekelo zibonisa umbhalo wemveli <input>s ngasentla, kodwa izimbo zokuqinisekisa iifomu ziyafumaneka kulawulo lwethu lwefom yesiko, kananjalo.

Umzekelo umbhalo wengxelo ongasebenziyo
Umzekelo ongakumbi wombhalo wengxelo ongasebenziyo
Umzekelo ongasebenziyo impendulo ekhethiweyo yesiko
Umzekelo wengxelo yefayile yesiko engasebenziyo
<form class="was-validated">
  <div class="custom-control custom-checkbox mb-3">
    <input type="checkbox" class="custom-control-input" id="customControlValidation1" required>
    <label class="custom-control-label" for="customControlValidation1">Check this custom checkbox</label>
    <div class="invalid-feedback">Example invalid feedback text</div>
  </div>

  <div class="custom-control custom-radio">
    <input type="radio" class="custom-control-input" id="customControlValidation2" name="radio-stacked" required>
    <label class="custom-control-label" for="customControlValidation2">Toggle this custom radio</label>
  </div>
  <div class="custom-control custom-radio mb-3">
    <input type="radio" class="custom-control-input" id="customControlValidation3" name="radio-stacked" required>
    <label class="custom-control-label" for="customControlValidation3">Or toggle this other custom radio</label>
    <div class="invalid-feedback">More example invalid feedback text</div>
  </div>

  <div class="form-group">
    <select class="custom-select" required>
      <option value="">Open this select menu</option>
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
    </select>
    <div class="invalid-feedback">Example invalid custom select feedback</div>
  </div>

  <div class="custom-file">
    <input type="file" class="custom-file-input" id="validatedCustomFile" required>
    <label class="custom-file-label" for="validatedCustomFile">Choose file...</label>
    <div class="invalid-feedback">Example invalid custom file feedback</div>
  </div>
</form>

Iingcebiso

Ukuba uyilo lwefomu yakho luyakuvumela, ungatshintshanisa .{valid|invalid}-feedbackiiklasi .{valid|invalid}-tooltipkwiiklasi ukubonisa ingxelo yokuqinisekisa kwisixhobo esinesitayile sesixhobo. Qinisekisa ukuba unomzali position: relativeophezu kwayo ukuze abeke incam yesixhobo. Kulo mzekelo ungezantsi, iiklasi zethu zekholomu sezinayo le nto, kodwa iprojekthi yakho inokufuna enye indlela yokuseta.

Looks good!
Looks good!
@
Please choose a unique and valid username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.
<form class="needs-validation" novalidate>
  <div class="form-row">
    <div class="col-md-4 mb-3">
      <label for="validationTooltip01">First name</label>
      <input type="text" class="form-control" id="validationTooltip01" placeholder="First name" value="Mark" required>
      <div class="valid-tooltip">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationTooltip02">Last name</label>
      <input type="text" class="form-control" id="validationTooltip02" placeholder="Last name" value="Otto" required>
      <div class="valid-tooltip">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationTooltipUsername">Username</label>
      <div class="input-group">
        <div class="input-group-prepend">
          <span class="input-group-text" id="validationTooltipUsernamePrepend">@</span>
        </div>
        <input type="text" class="form-control" id="validationTooltipUsername" placeholder="Username" aria-describedby="validationTooltipUsernamePrepend" required>
        <div class="invalid-tooltip">
          Please choose a unique and valid username.
        </div>
      </div>
    </div>
  </div>
  <div class="form-row">
    <div class="col-md-6 mb-3">
      <label for="validationTooltip03">City</label>
      <input type="text" class="form-control" id="validationTooltip03" placeholder="City" required>
      <div class="invalid-tooltip">
        Please provide a valid city.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationTooltip04">State</label>
      <input type="text" class="form-control" id="validationTooltip04" placeholder="State" required>
      <div class="invalid-tooltip">
        Please provide a valid state.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationTooltip05">Zip</label>
      <input type="text" class="form-control" id="validationTooltip05" placeholder="Zip" required>
      <div class="invalid-tooltip">
        Please provide a valid zip.
      </div>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>

Iifom eziqhelekileyo

Ukuze wenze ngokwezifiso ngakumbi kunye nokuhambelana kwesikhangeli, sebenzisa izinto zethu zefom yesiko ngokupheleleyo ukuze ubuyisele ukusilela kwesikhangeli. Zakhelwe phezu kwesemantic kunye nophawu olufikelelekayo, ke zilutshintsho oluluqilima lwalo naluphi na ulawulo lwefom olungagqibekanga.

Iibhokisi zokutshekisha kunye noonomathotholo

Ibhokisi nganye yokukhangela kunye nerediyo isongelwe <div>kunye nomntakwenu <span>ukwenza ulawulo lwethu lwesiko <label>kunye nesicatshulwa esikhaphayo. Ngokwesakhiwo, le yindlela efanayo neyethu engagqibekanga .form-check.

Sisebenzisa umkhethi wabazalwana ( ~) kuwo onke <input>amazwe ethu-nje- :checkedukulungisa ngokufanelekileyo isalathisi sethu sefom yesiko. Xa zidityaniswe .custom-control-labelneklasi, singenza kwakhona isimbo sokubhaliweyo kumba ngamnye ngokusekelwe <input>kwimeko.

Sifihla okungagqibekanga <input>kunye opacitykwaye sisebenzise .custom-control-labelukwakha isalathi sefomu yesiko esitsha endaweni yaso ::beforekunye ::after. Ngelishwa asikwazi ukwakha isiko ukusuka nje <input>ngenxa yokuba i-CSS contentayisebenzi kuloo nto.

Kwiimeko ezikhangelweyo, sisebenzisa ii-icon ze-SVG ezizinzisiweyo ze-base64 ukusuka kwi- Open iconic . Oku kusinika olona lawulo lulungileyo lwesitayile kunye nokubeka kwindawo kuzo zonke iibhrawuza kunye nezixhobo.

Iibhokisi zokukhangela

<div class="custom-control custom-checkbox">
  <input type="checkbox" class="custom-control-input" id="customCheck1">
  <label class="custom-control-label" for="customCheck1">Check this custom checkbox</label>
</div>

Iibhokisi zokukhangela eziqhelekileyo zinokusebenzisa :indeterminateudidi lwepseudo xa lucwangciswe ngesandla ngeJavaScript (akukho phawu loyelelwano lukhoyo lweHTML lokuyikhankanya).

Ukuba usebenzisa i-jQuery, into efana nale kufuneka yanele:

$('.your-checkbox').prop('indeterminate', true)

Oonomathotholo

<div class="custom-control custom-radio">
  <input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
  <label class="custom-control-label" for="customRadio1">Toggle this custom radio</label>
</div>
<div class="custom-control custom-radio">
  <input type="radio" id="customRadio2" name="customRadio" class="custom-control-input">
  <label class="custom-control-label" for="customRadio2">Or toggle this other custom radio</label>
</div>

Nomgca

<div class="custom-control custom-radio custom-control-inline">
  <input type="radio" id="customRadioInline1" name="customRadioInline1" class="custom-control-input">
  <label class="custom-control-label" for="customRadioInline1">Toggle this custom radio</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
  <input type="radio" id="customRadioInline2" name="customRadioInline1" class="custom-control-input">
  <label class="custom-control-label" for="customRadioInline2">Or toggle this other custom radio</label>
</div>

Kukhubazekile

Iibhokisi zokukhangela ezilungiselelweyo kunye nonomathotholo nazo zinokucinywa. Yongeza disableduphawu lwe-boolean <input>kunye nesalathisi esiqhelekileyo kunye nenkcazo yeleyibhile iya kwenziwa ngokuzenzekelayo.

<div class="custom-control custom-checkbox">
  <input type="checkbox" class="custom-control-input" id="customCheckDisabled" disabled>
  <label class="custom-control-label" for="customCheckDisabled">Check this custom checkbox</label>
</div>

<div class="custom-control custom-radio">
  <input type="radio" id="radio3" name="radioDisabled" id="customRadioDisabled" class="custom-control-input" disabled>
  <label class="custom-control-label" for="customRadioDisabled">Toggle this custom radio</label>
</div>

Khetha imenyu

Iimenyu eziqhelekileyo <select>zifuna kuphela iklasi yesiko, .custom-selectukuqala izimbo zesiko. Izimbo zesiko <select>zithintelwe kwinkangeleko yokuqala kwaye azinakuguqula i <option>s ngenxa yothintelo lomkhangeli zincwadi.

<select class="custom-select">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

Unokukhetha kwakhona kwizinto ezincinci kunye nezinkulu ezikhethiweyo ukuze utshatise amagalelo ethu okubhaliweyo alinganayo.

<select class="custom-select custom-select-lg mb-3">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

<select class="custom-select custom-select-sm">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

Uphawu multipleloyelelwano lukwaxhaswa:

<select class="custom-select" multiple>
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

Njengoko bunjalo sizeuphawu:

<select class="custom-select" size="3">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

Uluhlu

Yenza <input type="range">ulawulo lwesiko nge .custom-range. Ingoma (imvelaphi) kunye nobhontsi (ixabiso) zombini zenziwe ngohlobo olufanayo kuzo zonke izikhangeli. Njengoko kuphela i-IE kunye neFirefox exhasa "ukugcwalisa" umkhondo wabo ukusuka ekhohlo okanye ekunene kubhontsi njengendlela yokubonisa inkqubela phambili, asiyixhasi okwangoku.

<label for="customRange1">Example range</label>
<input type="range" class="custom-range" id="customRange1">

Uluhlu lwezimvo lunamaxabiso afihlakeleyo minkunye max- 0kunye 100, ngokulandelelanayo. Ungakhankanya amaxabiso amatsha kwabo basebenzisa i minkunye maxneempawu.

<label for="customRange2">Example range</label>
<input type="range" class="custom-range" min="0" max="5" id="customRange2">

Ngokungagqibekanga, amagalelo oluhlu "snap" ukuya kumaxabiso apheleleyo. Ukutshintsha oku, ungakhankanya stepixabiso. Kulo mzekelo ungezantsi, siphinda kabini inani lamanyathelo ngokusebenzisa step="0.5".

<label for="customRange3">Example range</label>
<input type="range" class="custom-range" min="0" max="5" step="0.5" id="customRange3">

Isikhangeli sefayile

Igalelo lefayile lolona luhlu lunzima kwaye lufuna iJavaScript eyongezelelweyo ukuba ungathanda ukuzidibanisa nomsebenzi Khetha ifayile... kwaye ukhethiweyo wegama lefayile elibhaliweyo.

<div class="custom-file">
  <input type="file" class="custom-file-input" id="customFile">
  <label class="custom-file-label" for="customFile">Choose file</label>
</div>

Sifihla ifayile engagqibekanga <input>sisebenzisa opacitykwaye endaweni yoko isitayile i <label>. Iqhosha liyenziwa kwaye libekwe nge ::after. Okokugqibela, sibhengeza u-a widthkunye heightnakwisithuba <input>esifanelekileyo somxholo ongqongileyo.

Ukuguqulela okanye ukulungisa imitya

I :lang()-pseudo-class isetyenziselwa ukuvumela uguqulelo lombhalo "Khangela" kwezinye iilwimi. Khipha ngaphezulu okanye yongeza amangeniso $custom-file-textkuguqulo lweSass ngethegi yolwimi olufanelekileyo kunye neentambo zasekuhlaleni. Iintambo zesiNgesi zinokulungiswa ngendlela efanayo. Umzekelo, nantsi indlela umntu anokongeza ngayo inguqulelo yeSpanish (ikhowudi yolwimi lwesiSpanish ithi es):

$custom-file-text: (
  en: "Browse",
  es: "Elegir"
);

Nantsi lang(es)intshukumo kwigalelo lefayile yesiko loguqulelo lwesiSpanish:

<div class="custom-file">
  <input type="file" class="custom-file-input" id="customFileLang" lang="es">
  <label class="custom-file-label" for="customFileLang">Seleccionar Archivo</label>
</div>

Kuya kufuneka usete ulwimi loxwebhu lwakho (okanye umthi ongezantsi walo) ngokuchanekileyo ukuze okubhaliweyo okuchanekileyo kuboniswe. Oku kunokwenziwa kusetyenziswa uphawu loyelelwano langlwento<html> okanye Content-Languageisihloko seHTTP , phakathi kwezinye iindlela.