Pen Settings



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


Babel includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


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.


                <!doctype html>
<html ng-app="form" >
  <meta charset="utf-8">
    <body ng-controller="FormCtrl">
      <form name="myForm">
        <input-form type="{{formData.type}}" rules="formData.rules" label="{{formData.label}}" param="formData.param" trim="{{formData.trim}}" placeholder="{{formData.placeholder}}" show-error="formData.showError" clearable="formData.clearable"></input-form>



                /* .searchclear {
    position: absolute;
    right: 5px;
    top: 0;
    bottom: 0;
    height: 14px;
    margin: auto;
    font-size: 14px;
    cursor: pointer;
    color: #ccc;
}   */


                var app = angular.module('form', []);

/* Controllers */
// patternとmaxlengthを併用する場合、patternが優先される
function FormCtrl($scope) {
  $scope.formData = {
    label: "label1",
    placeholder: 'placeholderだよ',
    param: "aaa",
    trim: false,
    clearable: true,
    type: "text",
    showError: true,
    rules: {
      required: {
        status: true,
        message: 'required'
      minlength: { 
        min: 2,
        message: 'min'
      maxlength: {
        max: 10,
        message: 'max'
      regex: {
        message: 'pattern',
        pattern: /^[0-9]{3}-[0-9]{4}$/

// 入力値がvalidationに引っかかっている場合、paramはundefinedになる
// placeholder="{{placeholder}}" ng-attr-placeholder="{{placeholder}}"
// そのためpatternの処理のみ別で行う
app.directive('inputForm', function() {
  var scope, linkFn, template, success, checkError, clearText;
  template = '{{clearable}}<div class="form-group"><label class="col-sm-3 control-label">{{label}}</label><div class="col-sm-9"><input placeholder="{{placeholder}}" ng-model="param" ng-required="rules.required.status" ng-maxlength="rules.maxlength.max" ng-minlength="rules.minlength.min" ng-trim="trim"><span ng-show="clearable && param" ng-click="clearText()" form-control-feedback" uib-tooltip="clear">x</span><div class="error-messages" ng-show="showError && error && dirty"><div ng-show="errors.required">{{rules.required.message}}</div><div ng-show="errors.pattern">{{rules.regex.message}}</div><div ng-show="errors.maxlength">{{rules.maxlength.message}}</div></div></div></div>';

  scope = {
    label: '@',
    placeholder: '@',
    trim: '@',
    clearable: '=',
    showError: '=',
    rules: '=',
    param: '='
  linkFn = function(scope, el, attrs, formCtrl) {
    var regexResult;
    scope.clearText = function() {
      scope.param = '';
    if ( formCtrl.$name === undefined ) throw new Error('please set form unique name');
    scope.errors = formCtrl.$error;
    scope.$watch('param', function(newValue, oldValue) {
      scope.errors.pattern = false;
      scope.error = formCtrl.$invalid;
      regexResult = scope.rules.regex.pattern.test(newValue);
      if ( newValue && !regexResult ) {
         scope.error = !regexResult;
         scope.errors.pattern = !regexResult;
      scope.dirty = formCtrl.$dirty
  return {
    restrict: 'E',
    scope: scope,
    template: template,
    require: '^form',
    link: linkFn