python - How to make Bootstrap file browse button using django-crispy-forms -


here django forms.py script, using django-crispy-forms

#!/usr/bin/env python django import forms .models import method1 crispy_forms.helper import formhelper crispy_forms.layout import submit, layout  class method1form(forms.modelform):      def __init__(self, *args, **kwargs):         """ use wrapping bootstrap         crispy stuff.         """         super(method1form, self).__init__(*args, **kwargs)         self.helper = formhelper()         self.helper.form_id = 'id-method1form'         self.helper.form_class =  'form-horizontal'         self.helper.label_class = 'col-lg-2'         self.helper.field_class = 'col-lg-8'         self.helper.form_method = 'post'         self.fields['inputfile_param'].label = "input file"         self.fields['species_param'].label = "species"         self.fields['norm_mode_param'].label = "normalization"         self.fields['logscale_param'].label = "log scale"         self.helper.layout = layout(                 'inputfile_param',                 'species_param',                 'norm_mode_param',                 'logscale_param',           )         self.helper.add_input(submit('submit', 'submit')) 

i can create following form:

enter image description here

as shown there, i'd make browse button bootstrap style. how can achieve that?

i'm thinking of this:

enter image description here

complete html rendered django looks this:

/* stuff django-crispy */  .asteriskfield {          display: none;  }      .form-control {      font-size:18px;      font-family:  "helvetica neue",helveticaneue;  }    .form-horizontal {      padding-left: 120px;      padding-right: 130px;      font-size:20px;      font-family:  "helvetica neue",helveticaneue;  }
<!doctype html>  <html>          <head>         <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>         <meta charset="utf-8">         </head>      <body>           <!--- display form -->          <form  id="id-method1form" class="form-horizontal" method="post"  enctype="multipart/form-data"> <input type='hidden' name='csrfmiddlewaretoken' value='jdujvarwokoxbqmoesashtadntlwjs5u' /> <div id="div_id_inputfile_param" class="form-group"> <label for="id_inputfile_param" class="control-label col-lg-2 requiredfield">                  input file<span class="asteriskfield">*</span> </label> <div class="controls col-lg-8"> <input class="clearablefileinput" id="id_inputfile_param" name="inputfile_param" type="file" /> </div> </div> <div id="div_id_species_param" class="form-group"> <label for="id_species_param" class="control-label col-lg-2 requiredfield">                  species<span class="asteriskfield">*</span> </label> <div class="controls col-lg-8"> <select class="select form-control" id="id_species_param" name="species_param">  <option value="mouse" selected="selected">mouse</option>  <option value="human">human</option>  </select> </div> </div> <div id="div_id_norm_mode_param" class="form-group"> <label for="id_norm_mode_param" class="control-label col-lg-2 requiredfield">                  normalization<span class="asteriskfield">*</span> </label> <div class="controls col-lg-8"> <select class="select form-control" id="id_norm_mode_param" name="norm_mode_param">  <option value="genecount_norm" selected="selected">gene count</option>  <option value="totalscore_norm">total score</option>  </select> </div> </div> <div class="form-group"> <div class="controls col-lg-offset-2 col-lg-8"> <div id="div_id_logscale_param" class="checkbox"> <label for="id_logscale_param" class=""> <input class="checkboxinput" id="id_logscale_param" name="logscale_param" type="checkbox" />                      log scale                                                                      </label> </div> </div> </div> <div class="form-group"> <div class="aab controls col-lg-2"></div> <div class="controls col-lg-8"> <input type="submit"      name="submit"      value="submit"                class="btn btn-primary"          id="submit-id-submit"                  /> </div> </div> </form>        <!--- end form display-->          </body>      </html>

i know old post 1 interested, crispy forms has in documentation:

 fieldwithbuttons: can create input connected buttons:   fieldwithbuttons('field_name', strictbutton("go!")) 

enter image description here

this in docs crispy forms bootstrap layout objects


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -