in English

Siffofin

Misalai da jagororin amfani don salon sarrafa nau'i, zaɓuɓɓukan shimfidawa, da abubuwan haɗin kai na al'ada don ƙirƙirar nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan nau'ikan abubuwan da aka tsara za a iya yin zaɓin zaɓi.

Dubawa

Gudanar da fom ɗin Bootstrap yana faɗaɗa kan salon fasalin mu da aka sake yi tare da azuzuwan. Yi amfani da waɗannan azuzuwan don ficewa cikin keɓancewar nunin su don ƙarin daidaiton ma'ana a cikin masu bincike da na'urori.

Tabbatar amfani da typesifa mai dacewa akan duk abubuwan shigarwa (misali, emaildon adireshin imel ko numberdon bayanin lamba) don cin gajiyar sabbin abubuwan sarrafawa kamar tabbatarwa imel, zaɓin lamba, da ƙari.

Anan ga misali mai sauri don nuna salon sigar Bootstrap. Ci gaba da karantawa don takaddun azuzuwan da ake buƙata, shimfidar tsari, da ƙari.

Ba za mu taɓa raba imel ɗinku da wani ba.
<form>
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
    <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">
  </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>

Gudanar da tsari

Sarrafa nau'ikan rubutu-kamar <input>s, <select>s, da <textarea>s-an tsara su tare da .form-controlajin. An haɗa da salo don bayyanar gaba ɗaya, yanayin mayar da hankali, girman girman, da ƙari.

Tabbatar bincika siffofin mu na al'ada don ƙarin salon <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>

Don shigar da fayil, musanya .form-controldon .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>

Girman girma

Saita tsayi ta amfani da azuzuwan kamar .form-control-lgda .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>

Karatu kawai

Ƙara readonlysifa ta boolean akan shigarwa don hana gyara ƙimar shigarwar. Abubuwan da ake karantawa kawai suna bayyana masu sauƙi (kamar abubuwan da aka kashe), amma suna riƙe daidaitaccen siginan kwamfuta.

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

Karatun rubutu kawai

Idan kana son samun <input readonly>abubuwa a cikin nau'in fom ɗinka da aka tsara su azaman rubutu na fili, yi amfani da .form-control-plaintextajin don cire salon sigar filin da aka saba da kuma adana daidaitaccen gefe da padding.

<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">
    </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>

Abubuwan Shigarwa

Saita shigarwar kewayon kewayon a kwance ta amfani da .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>

Akwatunan rajista da rediyo

Akwatunan rajistan shiga da rediyo an inganta su tare da taimakon .form-check, aji ɗaya don nau'ikan shigarwar guda biyu waɗanda ke inganta shimfidawa da halayen abubuwan HTML ɗin su . Akwatunan rajista don zaɓar ɗaya ko zaɓuɓɓuka da yawa a cikin jeri, yayin da rediyo ke zaɓin zaɓi ɗaya daga mutane da yawa.

Akwatunan rajistan nakasassu da rediyo suna tallafawa. Siffar disabledza ta yi amfani da launi mai sauƙi don taimakawa wajen nuna yanayin shigarwar.

Akwatunan rajistan shiga da maɓallan rediyo suna goyan bayan ingantaccen tsari na tushen HTML kuma suna ba da taƙaitacciyar tambura masu isa. Don haka, <input>s ɗinmu da namu <label>abubuwa ne na 'yan uwan ​​juna sabanin na <input>cikin <label>. Wannan ɗan karin magana ne kamar yadda dole ne ka ƙayyade idda forsifofi don alaƙa <input>da <label>.

Tsohuwar (tarage)

Ta hanyar tsoho, kowane adadin akwatunan rajistan shiga da rediyon da ke da 'yan'uwan nan da nan za a jera su a tsaye da sarari tare da .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>

Layin layi

Akwatunan bincike na rukuni ko radiyo akan layi ɗaya a kwance ta ƙara .form-check-inlinezuwa kowane .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>

Ba tare da lakabi ba

Ƙara .position-staticzuwa abubuwan da ke ciki .form-checkwaɗanda ba su da kowane rubutun lakabi. Ka tuna har yanzu samar da wani nau'i na suna don fasahar taimako (misali, ta amfani da 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>

Tsarin tsari

Tunda Bootstrap ya shafi display: blockkuma width: 100%kusan dukkan nau'ikan sarrafa nau'ikan mu, fom ɗin za su tari ta tsohuwa a tsaye. Ana iya amfani da ƙarin azuzuwan don bambanta wannan shimfidar wuri bisa kowane tsari.

Samar da ƙungiyoyi

Ajin .form-groupita ce hanya mafi sauƙi don ƙara wasu tsari zuwa siffofi. Yana ba da nau'i mai sassauƙa wanda ke ƙarfafa ƙungiyoyi masu dacewa na lakabi, sarrafawa, rubutun taimako na zaɓi, da samar da saƙon tabbatarwa. Ta hanyar tsoho yana aiki ne kawai margin-bottom, amma yana ɗaukar ƙarin salo a cikin .form-inlineyadda ake buƙata. Yi amfani da shi tare da <fieldset>s, <div>s, ko kusan kowane abu.

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

Tsarin tsari

Za a iya gina ƙarin hadaddun siffofin ta amfani da azuzuwan grid ɗin mu. Yi amfani da waɗannan don shimfidar tsari waɗanda ke buƙatar ginshiƙai da yawa, faɗin faɗin daban-daban, da ƙarin zaɓuɓɓukan jeri.

<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>

Tsarin layi

Hakanan kuna iya musanya .rowdon .form-row, bambancin daidaitaccen layin mu wanda ya ƙetare tsoffin ginshiƙan ginshiƙan don ƙarami kuma mafi ƙanƙanta shimfidu.

<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>

Hakanan za'a iya ƙirƙira ƙarin rikitattun shimfidu tare da tsarin grid.

<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">
    </div>
    <div class="form-group col-md-6">
      <label for="inputPassword4">Password</label>
      <input type="password" class="form-control" id="inputPassword4">
    </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>

Siffar kwance

Ƙirƙiri nau'i na kwance tare da grid ta ƙara .rowajin don samar da ƙungiyoyi da amfani da .col-*-*azuzuwan don tantance faɗin alamunku da abubuwan sarrafawa. Tabbatar ƙara .col-form-labelzuwa <label>s ɗin ku don haka suna tsaye a tsaye tare da abubuwan sarrafa nau'ikan su.

A wasu lokuta, ƙila kuna buƙatar amfani da gefe ko abubuwan amfani don ƙirƙirar daidaitattun daidaiton da kuke buƙata. Misali, mun cire alamar padding-topshigar da rediyon mu da aka toshe don ingantacciyar hanyar daidaita tushen rubutun.

Rediyo
<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">
    </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">
    </div>
  </div>
  <fieldset class="form-group row">
    <legend class="col-form-label col-sm-2 float-sm-left 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>
  </fieldset>
  <div class="form-group row">
    <div class="col-sm-10 offset-sm-2">
      <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>
Girman nau'in lakabin kwance

Tabbatar amfani da .col-form-label-smko .col-form-label-lgzuwa ga <label>s ko <legend>s ɗin ku don bi daidai girman girman .form-control-lgda .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>

Girman ginshiƙi

Kamar yadda aka nuna a cikin misalan da suka gabata, tsarin grid ɗinmu yana ba ku damar sanya kowane adadin .cols a cikin wani .rowko .form-row. Za su raba faɗin da ke akwai daidai tsakanin su. Hakanan kuna iya zaɓar juzu'in ginshiƙan ku don ɗaukar sarari ko žasa, yayin da sauran .cols ɗin suka raba daidai da sauran, tare da takamaiman azuzuwan shafi kamar .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>

Girman kai ta atomatik

Misalin da ke ƙasa yana amfani da kayan aikin flexbox don a tsaye a tsakiya abubuwan da ke ciki da canje-canje .colzuwa ta .col-autoyadda ginshiƙan ku kawai su ɗauki sarari gwargwadon buƙata. Sanya wata hanya, ginshiƙi yana girman kansa bisa abubuwan da ke ciki.

@
<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>

Kuna iya sake haɗa wannan tare da takamaiman azuzuwan shafi.

@
<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>

Kuma ba shakka ana tallafawa sarrafa tsari na al'ada .

<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>

Siffofin layi

Yi amfani da .form-inlineajin don nuna jerin lakabi, sarrafawar tsari, da maɓalli a jere ɗaya a kwance. Gudanar da tsari a cikin siffofin layi ya bambanta kaɗan daga tsoffin jihohin su.

  • Sarrafa su ne display: flex, ruguza duk wani farin sarari na HTML kuma yana ba ku damar samar da sarrafa jeri tare da tazara da kayan aikin flexbox .
  • Ƙungiyoyin sarrafawa da shigarwa suna karɓa width: autodon soke tsohowar Bootstrap width: 100%.
  • Sarrafa yana bayyana layi ɗaya kawai a cikin wuraren kallo waɗanda ke da faɗin aƙalla 576px don lissafin kunkuntar wuraren kallo akan na'urorin hannu.

Kuna iya buƙatar magance nisa da jeri na kowane nau'i na sarrafa nau'i tare da abubuwan amfani tazara (kamar yadda aka nuna a ƙasa). A ƙarshe, tabbatar da haɗawa koyaushe <label>tare da kowane nau'i sarrafa nau'i, ko da kuna buƙatar ɓoye shi daga baƙi marasa karanta allo tare da .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>

Hakanan ana goyan bayan sarrafa fom na al'ada da zaɓi.

<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>
Madadin maɓallan ɓoye

Fasaha masu taimako kamar masu karanta allo za su sami matsala tare da fom ɗinku idan ba ku haɗa da lakabin kowane shigarwa ba. Don waɗannan nau'ikan layi, zaku iya ɓoye alamun ta amfani da .sr-onlyajin. Akwai ƙarin hanyoyin hanyoyin samar da lakabi don fasahar taimako, kamar aria-label, aria-labelledbyko titlesifa. Idan babu ɗayan waɗannan, fasahar taimako na iya yin amfani da placeholdersifa, idan akwai, amma lura cewa placeholderba a ba da shawarar amfani da azaman madadin wasu hanyoyin yin lakabi ba.

Taimako rubutu

Ana iya ƙirƙirar rubutun taimako na toshewa a cikin nau'i ta amfani da .form-text(wanda aka sani a baya .help-blocka v3). Za a iya aiwatar da rubutun taimakon layi cikin sassauƙa ta amfani da kowane ɓangaren HTML na layi da azuzuwan masu amfani kamar .text-muted.

Haɗa rubutun taimako tare da sarrafa tsari

Rubutun taimako ya kamata a haɗa shi a fili tare da sarrafa nau'i wanda ya shafi amfani da aria-describedbysifa. Wannan zai tabbatar da cewa fasahar taimako-kamar masu karanta allo-zasu sanar da wannan rubutun taimako lokacin da mai amfani ya mai da hankali ko shigar da sarrafawa.

Ana iya tsara rubutun taimako da ke ƙasa abubuwan shigarwa da .form-text. Wannan ajin ya haɗa display: blockda ƙara wasu babban gefe don sauƙin tazara daga abubuwan da ke sama.

Dole ne kalmar wucewar ku ta kasance tsawon haruffa 8-20, ta ƙunshi haruffa da lambobi, kuma kada ta ƙunshi sarari, haruffa na musamman, ko 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>

Rubutun cikin layi na iya amfani da kowane nau'in HTML na layi na yau da kullun (zama a <small>, <span>, ko wani abu dabam) ba tare da komai ba face aji mai amfani.

Dole ne ya zama tsayin haruffa 8-20.
<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>

Siffofin naƙasassu

Ƙara disabledsifa ta boolean akan shigarwa don hana hulɗar mai amfani da sanya ta zama mai sauƙi.

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

Ƙara disabledsifa zuwa <fieldset>don kashe duk abubuwan sarrafawa a ciki.

An kashe misalin saitin filin
<form>
  <fieldset disabled>
    <legend>Disabled fieldset example</legend>
    <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-group">
      <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>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </fieldset>
</form>
Caveat tare da anga

Masu bincike suna kula da duk wani tsari na asali ( <input>, <select>, da <button>abubuwa) a cikin <fieldset disabled>nakasassu, suna hana mu'amalar maɓalli da linzamin kwamfuta a kansu.

Koyaya, idan fom ɗin ku kuma ya haɗa da abubuwa masu kama da maɓalli na al'ada kamar su <a ... class="btn btn-*">, waɗannan za a ba su salo ne kawai na pointer-events: none. Kamar yadda aka gani a cikin sashe game da yanayin nakasa don maɓalli (kuma musamman a cikin ƙaramin yanki don abubuwan anga), wannan kadarar ta CSS ba ta riga ta daidaita ba kuma ba ta da cikakken goyan bayanta a cikin Internet Explorer 10. Har ila yau, za a sami ikon sarrafa tushen anka. mai da hankali kuma mai iya aiki ta amfani da madannai. Dole ne ku canza waɗannan sarrafawa da hannu ta ƙara tabindex="-1"don hana su karɓar mayar da hankali da kuma aria-disabled="disabled"nuna alamar jiharsu zuwa fasahar taimako.

Daidaita-browser

Yayin da Bootstrap zai yi amfani da waɗannan salon a cikin duk masu bincike, Internet Explorer 11 da ƙasa ba sa cikakken goyon bayan disabledsifa akan <fieldset>. Yi amfani da JavaScript na al'ada don kashe saitin filin a cikin waɗannan masu binciken.

Tabbatarwa

Bayar da ra'ayi mai mahimmanci, mai iya aiki ga masu amfani da ku tare da ingantaccen tsari na HTML5- akwai a cikin duk masu binciken mu masu goyan baya . Zaɓi daga bayanan ingantattun bayanan mai bincike, ko aiwatar da saƙon na al'ada tare da ginanniyar azuzuwan mu da JavaScript mai farawa.

Muna sane da cewa a halin yanzu salon tabbatarwa na al'ada na abokin ciniki da nasihun kayan aiki ba su samuwa, tunda ba a fallasa su ga fasahar taimako. Yayin da muke aiki kan mafita, muna ba da shawarar ko dai ta yin amfani da zaɓin gefen uwar garken ko hanyar tabbatar da mashigar tsohuwa.

Yadda yake aiki

Anan ga yadda ingantaccen tsari ke aiki tare da Bootstrap:

  • Ana amfani da ingantaccen tsarin HTML ta hanyar azuzuwan ɓarna biyu na CSS, :invalidda :valid. Ya shafi <input>, <select>, da <textarea>abubuwa.
  • Bootstrap ya keɓanta da salo :invalidda :validsalo zuwa ajin iyaye .was-validated, yawanci ana amfani da su ga <form>. In ba haka ba, kowane filin da ake buƙata ba tare da ƙima yana nunawa a matsayin mara inganci akan nauyin shafi. Ta wannan hanyar, zaku iya zaɓar lokacin kunna su (yawanci bayan an yi ƙoƙarin ƙaddamar da fom).
  • Don sake saita bayyanar fom (misali, a cikin yanayin ƙaddamar da tsari mai ƙarfi ta amfani da AJAX), cire .was-validatedajin daga <form>sake bayan ƙaddamarwa.
  • A matsayin koma baya, .is-invalidkuma .is-validana iya amfani da azuzuwan maimakon azuzuwan ƙididdiga don tabbatar da gefen uwar garken . Ba sa buƙatar .was-validatedajin iyaye.
  • Saboda ƙuntatawa a cikin yadda CSS ke aiki, ba za mu iya (a halin yanzu) amfani da salo ga <label>wanda ya zo gaban sarrafa tsari a cikin DOM ba tare da taimakon JavaScript na al'ada ba.
  • Duk masu bincike na zamani suna goyan bayan ingantaccen ingantaccen API , jerin hanyoyin JavaScript don tabbatar da sarrafa tsari.
  • Saƙonnin mayar da martani na iya yin amfani da abubuwan da suka dace na burauza (mabambanta ga kowane mai bincike, kuma wanda ba a iya salo ta hanyar CSS) ko salon amsa namu na al'ada tare da ƙarin HTML da CSS.
  • Kuna iya ba da saƙon inganci na al'ada da su setCustomValiditya cikin JavaScript.

Tare da wannan a zuciya, yi la'akari da fa'idodin demos masu zuwa don salon ingantaccen sigar mu ta al'ada, azuzuwan gefen uwar garken zaɓi, da maƙasudin burauza.

Salon al'ada

Don saƙon ingantaccen tsari na Bootstrap na al'ada, kuna buƙatar ƙara novalidatesifa ta boolean zuwa <form>. Wannan yana hana tsoffin bayanan bayanan kayan aikin mai bincike, amma har yanzu yana ba da dama ga API ɗin ingantaccen tsari a JavaScript. Yi ƙoƙarin ƙaddamar da fom ɗin da ke ƙasa; JavaScript ɗin mu zai katse maɓallin ƙaddamarwa kuma ya ba da amsa gare ku. Lokacin ƙoƙarin ƙaddamarwa, za ku ga da :invalidkuma :validsalon da aka yi amfani da su akan sarrafa fom ɗin ku.

Salon amsa na al'ada suna amfani da launuka na al'ada, iyakoki, salon mayar da hankali, da gumakan bango don ingantacciyar hanyar sadarwa. Gumakan bango na <select>s suna samuwa kawai tare da .custom-select, kuma ba .form-control.

Yayi kyau!
Yayi kyau!
Da fatan za a samar da ingantaccen birni.
Da fatan za a zaɓi ingantacciyar yanayi.
Da fatan za a ba da ingantaccen zip.
Dole ne ku yarda kafin ƙaddamarwa.
<form class="needs-validation" novalidate>
  <div class="form-row">
    <div class="col-md-6 mb-3">
      <label for="validationCustom01">First name</label>
      <input type="text" class="form-control" id="validationCustom01" value="Mark" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-6 mb-3">
      <label for="validationCustom02">Last name</label>
      <input type="text" class="form-control" id="validationCustom02" value="Otto" required>
      <div class="valid-feedback">
        Looks good!
      </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" required>
      <div class="invalid-feedback">
        Please provide a valid city.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationCustom04">State</label>
      <select class="custom-select" id="validationCustom04" required>
        <option selected disabled value="">Choose...</option>
        <option>...</option>
      </select>
      <div class="invalid-feedback">
        Please select 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" 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>

Matsalolin Browser

Ba ku da sha'awar saƙon amsawa na tabbatarwa na al'ada ko rubuta JavaScript don canza halayen tsari? Da kyau, zaku iya amfani da abubuwan da ba a iya amfani da su ba. Gwada ƙaddamar da fom ɗin da ke ƙasa. Dangane da burauzar ku da kuma OS, zaku ga salon ra'ayi daban-daban.

Duk da yake waɗannan salon amsa ba za a iya sa su tare da CSS ba, har yanzu kuna iya keɓance rubutun ra'ayin ta hanyar JavaScript.

<form>
  <div class="form-row">
    <div class="col-md-6 mb-3">
      <label for="validationDefault01">First name</label>
      <input type="text" class="form-control" id="validationDefault01" value="Mark" required>
    </div>
    <div class="col-md-6 mb-3">
      <label for="validationDefault02">Last name</label>
      <input type="text" class="form-control" id="validationDefault02" value="Otto" required>
    </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" required>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationDefault04">State</label>
      <select class="custom-select" id="validationDefault04" required>
        <option selected disabled value="">Choose...</option>
        <option>...</option>
      </select>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationDefault05">Zip</label>
      <input type="text" class="form-control" id="validationDefault05" 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>

Gefen uwar garken

Muna ba da shawarar yin amfani da ingantaccen gefen abokin ciniki, amma idan kuna buƙatar ingantaccen gefen uwar garken, zaku iya nuna mara inganci da filayen fom tare .is-invalidda .is-valid. Lura cewa .invalid-feedbackkuma ana goyan bayan waɗannan azuzuwan.

Don filayen da ba daidai ba, tabbatar da cewa ba daidai ba amsa/saƙon kuskure yana da alaƙa da filin tsari mai dacewa ta amfani da aria-describedby. Wannan sifa tana ba da damar yin nuni fiye da ɗaya id, idan filin ya riga ya nuna ƙarin rubutu.

Yayi kyau!
Yayi kyau!
Da fatan za a samar da ingantaccen birni.
Da fatan za a zaɓi ingantacciyar yanayi.
Da fatan za a ba da ingantaccen zip.
Dole ne ku yarda kafin ƙaddamarwa.
<form>
  <div class="form-row">
    <div class="col-md-6 mb-3">
      <label for="validationServer01">First name</label>
      <input type="text" class="form-control is-valid" id="validationServer01" value="Mark" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-6 mb-3">
      <label for="validationServer02">Last name</label>
      <input type="text" class="form-control is-valid" id="validationServer02" value="Otto" required>
      <div class="valid-feedback">
        Looks good!
      </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" aria-describedby="validationServer03Feedback" required>
      <div id="validationServer03Feedback" class="invalid-feedback">
        Please provide a valid city.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationServer04">State</label>
      <select class="custom-select is-invalid" id="validationServer04" aria-describedby="validationServer04Feedback" required>
        <option selected disabled value="">Choose...</option>
        <option>...</option>
      </select>
      <div id="validationServer04Feedback" class="invalid-feedback">
        Please select 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" aria-describedby="validationServer05Feedback" required>
      <div id="validationServer05Feedback" 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" aria-describedby="invalidCheck3Feedback" required>
      <label class="form-check-label" for="invalidCheck3">
        Agree to terms and conditions
      </label>
      <div  id="invalidCheck3Feedback" class="invalid-feedback">
        You must agree before submitting.
      </div>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>

Abubuwan tallafi

Ana samun salon tabbatarwa don sarrafa nau'i mai zuwa da abubuwan haɗin gwiwa:

  • <input>s da <textarea>s.form-control
  • <select>s tare da .form-controlko.custom-select
  • .form-checks
  • .custom-checkboxs da .custom-radios
  • .custom-file
Da fatan za a shigar da saƙo a cikin yankin rubutu.
Misali rubutun amsa mara inganci
Ƙarin misali rubutu mara inganci
Misali na al'ada mara inganci zaɓi martani
Misali ra'ayin fayil na al'ada mara inganci
@
Misali bayanan shigar da ba daidai ba
Misali bayanan shigar da ba daidai ba
Misali bayanan shigar da ba daidai ba
<form class="was-validated">
  <div class="mb-3">
    <label for="validationTextarea">Textarea</label>
    <textarea class="form-control is-invalid" id="validationTextarea" placeholder="Required example textarea" required></textarea>
    <div class="invalid-feedback">
      Please enter a message in the textarea.
    </div>
  </div>

  <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="mb-3">
    <select class="custom-select" required>
      <option value="">Choose...</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 mb-3">
    <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>

  <div class="mb-3">
    <div class="input-group is-invalid">
      <div class="input-group-prepend">
        <span class="input-group-text" id="validatedInputGroupPrepend">@</span>
      </div>
      <input type="text" class="form-control is-invalid" aria-describedby="validatedInputGroupPrepend" required>
    </div>
    <div class="invalid-feedback">
      Example invalid input group feedback
    </div>
  </div>

  <div class="mb-3">
    <div class="input-group is-invalid">
      <div class="input-group-prepend">
        <label class="input-group-text" for="validatedInputGroupSelect">Options</label>
      </div>
      <select class="custom-select" id="validatedInputGroupSelect" required>
        <option value="">Choose...</option>
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
      </select>
    </div>
    <div class="invalid-feedback">
      Example invalid input group feedback
    </div>
  </div>

  <div class="input-group is-invalid">
    <div class="custom-file">
      <input type="file" class="custom-file-input" id="validatedInputGroupCustomFile" required>
      <label class="custom-file-label" for="validatedInputGroupCustomFile">Choose file...</label>
    </div>
    <div class="input-group-append">
       <button class="btn btn-outline-secondary" type="button">Button</button>
    </div>
  </div>
  <div class="invalid-feedback">
    Example invalid input group feedback
  </div>
</form>

Nasihun kayan aiki

Idan tsarin tsarin ku ya ba shi damar, za ku iya musanya .{valid|invalid}-feedbackazuzuwan don .{valid|invalid}-tooltipazuzuwan don nuna ra'ayoyin ingantawa a cikin salo mai salo na kayan aiki. Tabbatar cewa kuna da iyaye tare da position: relativeshi don saka kayan aiki. A cikin misalin da ke ƙasa, azuzuwan rukunin mu sun riga sun sami wannan, amma aikinku na iya buƙatar saitin madadin.

Yayi kyau!
Yayi kyau!
Da fatan za a samar da ingantaccen birni.
Da fatan za a zaɓi ingantacciyar yanayi.
Da fatan za a ba da ingantaccen zip.
<form class="needs-validation" novalidate>
  <div class="form-row">
    <div class="col-md-6 mb-3">
      <label for="validationTooltip01">First name</label>
      <input type="text" class="form-control" id="validationTooltip01" value="Mark" required>
      <div class="valid-tooltip">
        Looks good!
      </div>
    </div>
    <div class="col-md-6 mb-3">
      <label for="validationTooltip02">Last name</label>
      <input type="text" class="form-control" id="validationTooltip02" value="Otto" required>
      <div class="valid-tooltip">
        Looks good!
      </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" required>
      <div class="invalid-tooltip">
        Please provide a valid city.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationTooltip04">State</label>
      <select class="custom-select" id="validationTooltip04" required>
        <option selected disabled value="">Choose...</option>
        <option>...</option>
      </select>
      <div class="invalid-tooltip">
        Please select 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" required>
      <div class="invalid-tooltip">
        Please provide a valid zip.
      </div>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>

Keɓancewa

Ana iya keɓance jihohin tabbatarwa ta hanyar Sass tare da $form-validation-statestaswira. Ana cikin _variables.scssfayil ɗin mu, wannan taswirar Sass an kulle shi don samar da tsoffin jihohi valid/ tabbatarwa. invalidAn haɗa taswirar gida don keɓance launi da gunkin kowace jiha. Duk da yake babu wasu jihohi da masu bincike ke tallafawa, waɗanda ke amfani da salon al'ada na iya ƙara ƙarin ra'ayi mai rikitarwa cikin sauƙi.

Da fatan za a lura cewa ba mu bayar da shawarar keɓance waɗannan dabi'u ba tare da gyaggyara abin haɗin ba form-validation-state.

// Sass map from `_variables.scss`
// Override this and recompile your Sass to generate different states
$form-validation-states: map-merge(
  (
    "valid": (
      "color": $form-feedback-valid-color,
      "icon": $form-feedback-icon-valid
    ),
    "invalid": (
      "color": $form-feedback-invalid-color,
      "icon": $form-feedback-icon-invalid
    )
  ),
  $form-validation-states
);

// Loop from `_forms.scss`
// Any modifications to the above Sass map will be reflected in your compiled
// CSS via this loop.
@each $state, $data in $form-validation-states {
  @include form-validation-state($state, map-get($data, color), map-get($data, icon));
}

Tabbatarwar ƙungiyar shigar

Don gano abubuwan da ke buƙatar kusurwoyi masu zagaye a cikin ƙungiyar shigarwa tare da inganci, ƙungiyar shigarwa tana buƙatar ƙarin .has-validationaji.

<div class="input-group has-validation">
  <div class="input-group-prepend">
    <span class="input-group-text">@</span>
  </div>
  <input type="text" class="form-control" required>
  <div class="invalid-feedback">
    Please choose a username.
  </div>
</div>
@
Da fatan za a zaɓi sunan mai amfani.

Siffofin al'ada

Don ƙarin keɓancewa da daidaitawar burauza, yi amfani da abubuwan mu na al'ada gabaɗaya don maye gurbin abubuwan da suka dace. An gina su a saman nazarce-nazarce da alamar iya samun dama, don haka suna da ƙwaƙƙwaran musanyawa ga kowane nau'i na tsoho.

Akwatunan rajista da rediyo

Kowane akwati da rediyo <input>da <label>haɗin kai an naɗe su a cikin wani <div>don ƙirƙirar sarrafa mu na al'ada. A tsari, wannan hanya ɗaya ce ta tsoho .form-check.

Muna amfani da zaɓin ƴan uwa ( ~) ga duk <input>jihohinmu-kamar- :checkeddon yin salon ƙirar ƙirar mu da kyau. Lokacin da aka haɗa shi da .custom-control-labelajin, za mu iya kuma salon rubutun ga kowane abu dangane da yanayin <input>'yanayin.

Muna ɓoye tsoho <input>tare opacityda amfani da .custom-control-labeldon gina sabon alamar sigar al'ada a wurin sa tare ::beforeda ::after. Abin baƙin ciki ba za mu iya gina al'ada daya daga kawai <input>saboda CSS's contentba ya aiki a kan wannan kashi.

A cikin jihohin da aka bincika, muna amfani da gunkin SVG mai tushe64 daga Buɗe Iconic . Wannan yana ba mu mafi kyawun sarrafawa don salo da sakawa a cikin masu bincike da na'urori.

Akwatunan rajista

<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>

Akwatunan rajista na al'ada kuma na iya amfani da :indeterminateajin ƙididdiga lokacin da aka saita da hannu ta JavaScript (babu wani sifa na HTML don tantance shi).

Idan kana amfani da jQuery, wani abu kamar wannan ya isa:

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

Rediyo

<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>

Layin layi

<div class="custom-control custom-radio custom-control-inline">
  <input type="radio" id="customRadioInline1" name="customRadioInline" 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="customRadioInline" class="custom-control-input">
  <label class="custom-control-label" for="customRadioInline2">Or toggle this other custom radio</label>
</div>

An kashe

Hakanan za'a iya kashe akwatunan rajista da rediyo na musamman. Ƙara disabledsifa ta boolean zuwa ga <input>kuma alamar al'ada da bayanin alamar za a yi salo ta atomatik.

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

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

Sauyawa

Maɓalli yana da alamar akwati na al'ada amma yana amfani da .custom-switchajin don yin jujjuyawa. Sauyawa kuma suna goyan bayan disabledsifa.

<div class="custom-control custom-switch">
  <input type="checkbox" class="custom-control-input" id="customSwitch1">
  <label class="custom-control-label" for="customSwitch1">Toggle this switch element</label>
</div>
<div class="custom-control custom-switch">
  <input type="checkbox" class="custom-control-input" disabled id="customSwitch2">
  <label class="custom-control-label" for="customSwitch2">Disabled switch element</label>
</div>

Zaɓi menu

Menu na al'ada <select>yana buƙatar aji na al'ada kawai, .custom-selectdon jawo salo na al'ada. Salon al'ada sun iyakance ga <select>bayyanar farko kuma ba za su iya gyara <option>s ɗin ba saboda gazawar mai bincike.

<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>

Hakanan kuna iya zaɓar daga ƙanana da manyan zaɓaɓɓun al'ada don dacewa da madaidaitan abubuwan shigar da rubutu na mu.

<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>

Hakanan multipleana tallafawa sifa:

<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>

Kamar yadda sizesifa ce:

<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>

Rage

Ƙirƙirar <input type="range">sarrafawa na al'ada tare da .custom-range. Waƙar (bangon) da babban yatsan hannu (ƙimar) duk an tsara su don bayyana iri ɗaya a cikin masu bincike. Kamar yadda kawai IE da Firefox ke tallafawa "cika" waƙar su daga hagu ko dama na babban yatsa a matsayin hanyar nuna ci gaba a gani, ba mu goyan bayan sa a halin yanzu.

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

Abubuwan shigar da kewayon suna da fayyace ƙima don minda max- 0da 100, bi da bi. Kuna iya ƙayyade sabbin ƙima ga waɗanda ke amfani minda maxsifofi.

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

Ta hanyar tsoho, abubuwan shigar da kewayon “tsaye” zuwa ƙimar lamba. Don canza wannan, zaku iya ƙayyade stepƙima. A cikin misalin da ke ƙasa, muna ninka adadin matakan ta amfani da step="0.5".

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

Mai binciken fayil

Abubuwan plugin ɗin da aka ba da shawarar don haɓaka shigar da fayil na al'ada: bs-custom-file-input , abin da muke amfani da shi kenan a halin yanzu a cikin takaddun mu.

Shigar da fayil ɗin shine mafi girman gungun kuma yana buƙatar ƙarin JavaScript idan kuna son haɗa su da aikin Zaɓi fayil… da zaɓin rubutun sunan fayil.

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

Muna ɓoye tsoho fayil <input>ta hanyar opacitykuma a maimakon haka muna yin salon <label>. Ana ƙirƙira maɓallin kuma an sanya shi tare da ::after. A ƙarshe, muna ayyana a widthkuma heighta kan <input>madaidaicin tazara don abubuwan da ke kewaye.

Fassara ko keɓance igiyoyin da SCSS

Ana :lang()amfani da ajin karya don ba da izinin fassara rubutun “Bincike” zuwa wasu harsuna. Shake ko ƙara shigarwar zuwa $custom-file-textmadaidaicin Sass tare da alamar harshe mai dacewa da kirtani na gida. Za a iya keɓance igiyoyin Ingilishi iri ɗaya. Misali, ga yadda mutum zai iya ƙara fassarar Mutanen Espanya (lambar yaren Mutanen Espanya shine es):

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

Anan lang(es)aiki akan shigarwar fayil na al'ada don fassarar Mutanen Espanya:

<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>

Kuna buƙatar saita harshen takaddar ku (ko bishiyar ta) daidai domin a nuna madaidaicin rubutu. Ana iya yin wannan ta amfani da langsifa akan sifa <html>ko Content-Languagetaken HTTP , a tsakanin sauran hanyoyin.

Fassara ko keɓance igiyoyin da HTML

Bootstrap kuma yana ba da hanyar fassara rubutun "Bincike" a cikin HTML tare da data-browsesifa wanda za'a iya ƙarawa zuwa alamar shigar da al'ada (misali a cikin Yaren mutanen Holland):

<div class="custom-file">
  <input type="file" class="custom-file-input" id="customFileLangHTML">
  <label class="custom-file-label" for="customFileLangHTML" data-browse="Bestand kiezen">Voeg je document toe</label>
</div>