Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <h1>Find Empty Inputs</h1>
  <p>Find all empty inputs within specific panel with reusable validation scripts.</p>
  
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">Panel 1</h3>
    </div>
    <div class="panel-body">
      <div class="alert alert-warning">
        Please complete required fields marked in red.
      </div>
      <form>
        <div class="row">
          <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label">First Name</label>
              <input type="text" class="form-control" placeholder="Enter first name">
            </div>
          </div><!-- Col -->

          <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label">Last Name</label>
              <input type="text" class="form-control" placeholder="Enter last name">
            </div>
          </div><!-- Col -->
        </div><!-- Row -->

        <div class="row">
          <div class="col-sm-4">
            <div class="form-group">
              <label class="control-label">City</label>
              <input type="text" class="form-control" placeholder="Enter city">
            </div>
          </div><!-- Col -->

          <div class="col-sm-4">
            <div class="form-group">
              <label class="control-label">State</label>
              <input type="text" class="form-control" placeholder="Enter state">
            </div>
          </div><!-- Col -->

          <div class="col-sm-4">
            <div class="form-group">
              <label class="control-label">Zip</label>
              <input type="text" class="form-control" placeholder="Enter zip code">
            </div>
          </div><!-- Col -->
        </div><!-- Row -->
        
        <div class="row">
          <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label">Email address</label>
              <input type="email" class="form-control" placeholder="Enter email">
            </div>
          </div><!-- Col -->

          <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label">Password</label>
              <input type="password" class="form-control" placeholder="Password">
            </div>
          </div><!-- Col -->
        </div><!-- Row -->
      </form>
    </div>
    <div class="panel-footer">
      <div class="row">
        <div class="col-sm-12">
          <div class="pull-right">
            <button type="button" class="btn btn-default reset">Reset</button>
            <button type="button" class="btn btn-primary submit">Submit</button>
          </div>
        </div>
      </div>
    </div><!-- Panel Footer -->
  </div>
  
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">Panel 2</h3>
    </div>
    <div class="panel-body">
      <div class="alert alert-warning">
        Please complete required fields marked in red.
      </div>
      <form>
        <div class="row">
          <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label">First Name</label>
              <input type="text" class="form-control" placeholder="Enter first name">
            </div>
          </div><!-- Col -->

          <div class="col-sm-6">
            <div class="form-group">
              <label class="control-label">Last Name</label>
              <input type="text" class="form-control" placeholder="Enter last name">
            </div>
          </div><!-- Col -->
        </div><!-- Row -->

        <div class="row">
          <div class="col-sm-4">
            <div class="form-group">
              <label class="control-label">City</label>
              <input type="text" class="form-control" placeholder="Enter city">
            </div>
          </div><!-- Col -->

          <div class="col-sm-4">
            <div class="form-group">
              <label class="control-label">State</label>
              <input type="text" class="form-control" placeholder="Enter state">
            </div>
          </div><!-- Col -->

          <div class="col-sm-4">
            <div class="form-group">
              <label class="control-label">Zip</label>
              <input type="text" class="form-control" placeholder="Enter zip code">
            </div>
          </div><!-- Col -->
        </div><!-- Row -->
      </form>
    </div>
    <div class="panel-footer">
      <div class="row">
        <div class="col-sm-12">
          <div class="pull-right">
            <button type="button" class="btn btn-default reset">Reset</button>
            <button type="button" class="btn btn-primary submit">Submit</button>
          </div>
        </div>
      </div>
    </div><!-- Panel Footer -->
  </div>
</div>
              
            
!

CSS

              
                body {
  font-family: 'Open Sans', "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #444;
}
              
            
!

JS

              
                $('.alert').hide();

$('.submit').click(function () {
  // set variable that counts how many input fields are left blank
  var emptyInputs = $(this).closest('.panel').find('input').filter(function(){
                        return !$(this).val();
                    }).length;
  
  // if none of the input fields are left blank
  if (emptyInputs == 0) {
    // accept data and hide panel
    $(this).closest('.panel').hide();
  } 
  else {
    // within this panel, find all inputs
    $(this).closest('.panel').find("input").each(function () {
      var element = $(this);
      // if any input is empty  
      if (element.val() == "") {
        // add the has-error class to the .form-group parent div
        $(element).closest('.form-group').addClass('has-error');
        // and show alert box
        $(element).closest('.panel').find('.alert').show();
      }
    });
  }
});

// click reset to clear all fields, remove error class, hide alert
$('.reset').click(function () {
  $(this).closest('.panel').find("input").each(function () {
    $(this).val('');
    $(this).closest('.form-group').removeClass('has-error');
    $(this).closest('.panel').find('.alert').hide();
  });
})
              
            
!
999px

Console