Coder Social home page Coder Social logo

johannesjo / ng-fab-form Goto Github PK

View Code? Open in Web Editor NEW
172.0 14.0 25.0 3.34 MB

Convenient forms for Angular with no extra markup? Fabulous!

Home Page: https://johannesjo.github.io/ng-fab-form

License: MIT License

JavaScript 69.18% CSS 3.23% HTML 27.60%

ng-fab-form's Introduction

Build Status Coverage Status

ng-fab-form

Convenient forms for Angular with no extra markup? Fabulous!

AngularJS forms are pretty nice. But if you have worked with angular for a while, you'll find that the out of the box mechanics like the instant validation are far from perfect from the common users perspective. Furthermore you probably catch yourself declaring (and sometimes forgetting) the same stuff on and on again like giving a novalidate attribute, preventing submission for invalid forms or declaring a proper name attribute and worst of all: setting up validation messages again and again.

It is understandable why the angular-developers want to give us the freedom, of doing all this stuff in the most flexible manner, but most of the time you want to keep things consistent and not handle every form differently.ng-fab-form tries to help you with this with a reasonable default but highly configurable behavior for your forms.

Bug-reports or feature request as well as any other kind of feedback is highly welcome!

getting started

Install it via bower

bower install ng-fab-form -S

and add ngFabForm as dependency in your main module:

angular.module('yourApp',[
  'ngFabForm'
]);

That is all you need to do to get started.

features

Have a look at the DEMO or the plunkr!

Keep in mind that if you don't like one of the functionalities, ng-fab-form is build with customization in mind. It's possible to disable almost any feature easily in your app configuration.

List of Features:

  • Global (or individual) configurable validation messages (using ng-messages, see) to any element with a validation directive on it like required, ng-required, ng-pattern, ng-minlength and even new ones added.
  • Prevents submission of invalid forms
  • Completely disableable forms via a disable-form attribute
  • Show field validations after submit attempt
  • Prevent double submissions of forms when double clicked via a configurable delay
  • Total configurability: You not only can change or turn of any default setting you don't like, but the validation messages template gives you complete flexibility on when and how your error messages appear.
  • Works with any custom validation directive you have running in your project (as long as they're correctly working with the ngModel-Controller)
  • Provides you with resettable forms via the $resetForm method
  • Compatibility with most other form modules
  • Compatibility with the most popular translation modules
  • Provides an api to add custom validators
  • Adds a more reasonable email-validation
  • Adds name attributes based on ng-model, if none is set
  • Adds the novalidate attribute to forms
  • ngFabMatch-directive (e.g. for checking a repeated password)
  • Has support for async-validators and adds a nice interface to add new ones
  • Scrolls to and focuses the first form element with an error, if the submission fails

Useful companions

why choose ng-fab-form over another form helper module?

There are a lot of form builders and other modules with the intention of simplifying form handling out there. Why choose ng-fab-form then? First of all you likely will not have to choose one or the other as it should be compatible with every module using ngModel for validations and because you will probably be able to deactivate any conflicting functionalities (be sure to report incompatibilities).

The reason why ng-fab-form was build, is that the modules I tried either take only a small part of the repetitiveness out of your job or they take a framework-like approach and you're becoming very dependent on them, the markup they require and spit out, the functionalities they introduce and probably more important, those they don't introduce and those who hinder other features. This is not necessarily a bad thing and they might greatly improve your productivity, but the (non angular-canon) restrictions and rules they introduce make them too limited for some projects and less of a universal form tool, which can be used again and again.

This is why ng-fab-form focuses on the basic angular functions and tries to extend them application-wide, while always giving you the option to throw out what doesn't fit in. Worst case scenario: You completely remove ng-fab-form because you don't like it and then you're back to standard angular, with probably almost no effort spend, almost no time wasted.

manual installation and dependencies

Grab the minified ng-fab-form file from the dist folder. You also need to install ng-messags which is the only required dependency.

configuring default form options

Currently the configuration object of ng-fab-forms looks like this:

// validation template-url/templateId
// to disable validation completely set it false
validationsTemplate: 'default-validation-msgs.html',

// prevent submission of invalid forms
preventInvalidSubmit: true,

// prevent double clicks
preventDoubleSubmit: true,

// double click delay duration
preventDoubleSubmitTimeoutLength: 1000,

// show validation-messages on failed submit
setFormDirtyOnSubmit: true,

// autofocus first error-element
scrollToAndFocusFirstErrorOnSubmit: true,

// set in ms
scrollAnimationTime: 500,

// fixed offset for scroll to element
scrollOffset: -100,

// ***************************************************
// The following options are not configurable via the
// ngFabFormOptions-directive as they need to be
// available during the $compile-phase
// ***************************************************

// option to disable forms by wrapping them in a disabled <fieldset> element
disabledForms: true,

// option to disable ng-fab-form globally and use it only manually
// via the ng-fab-form directive
globalFabFormDisable: false,

// add noovalidate to forms
setNovalidate: true,

// set form-element names based on ngModel if not set
// NOTE: not changeable via ngFabFormOptions-directive as it needs to
// available during the $compile-phase
// NOTE2: name-attributes are required to be set here
// or manually for the validations to work
setNamesByNgModel: true,

// add asterisk to required fields; only
// works when the forms are NOT globally disabled
setAsteriskForRequiredLabel: false,

// asterisk string to be added if enabled
// requires setAsteriskForRequiredLabel-option set to true
asteriskStr: '*',

// the validation message prefix, results for the default state
// `validation-msg-required` or `validation-msg-your-custom-validation`
validationMsgPrefix: 'validationMsg',

// default email-regex, set to false to deactivate overwrite
emailRegex: /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/,

// in very rare cases (e.g. for some form-builders) your form
// controller might not be ready before your model-controllers are,
// for those instances set this option to true
watchForFormCtrl: false,

// name of the change event, change if there are conflicts
formChangeEvent: 'NG_FAB_FORM_OPTIONS_CHANGED'

// message template, used to create messages for custom validation messages
// created by validationMsgPrefix when there is no default ng-message for
// the validator in the main template. This allows you to one time append
// messages when validationMSgPrefix(+validator+) is set
createMessageElTplFn: function (sanitizedKey, attr)
{
    return '<li ng-message="' + sanitizedKey + '">' + attr + '</li>';
}

You can easily extend those configurations like this:

angular.module('exampleApp', [
    'ngFabForm'
])
    .config(function (ngFabFormProvider)
    {
        ngFabFormProvider.extendConfig({
            scrollToAndFocusFirstErrorOnSubmit: false,
            setNovalidate: false
        });
    });

multiple form configurations via ng-fab-form-options

validationsTemplate, preventInvalidSubmit, preventDoubleSubmit, preventDoubleSubmitTimeoutLength, setFormDirtyOnSubmit, scrollToAndFocusFirstErrorOnSubmit, scrollAnimationTime and scrollOffset can also be changed in real-time from your controllers or directives:

angular.module('exampleApp', [
'ngFabForm'
])
.controller('exampleCtrl', function ($scope, ngFabForm)
{
  $scope.customFormOptions = {
    validationsTemplate: 'your-tpl.html',
    preventInvalidSubmit: false,
    preventDoubleSubmit: false,
    setFormDirtyOnSubmit: true,
    scrollToAndFocusFirstErrorOnSubmit: true,
    scrollAnimationTime: 900,
    scrollOffset: -100,
  };
});

And in your template:

<form ng-fab-form-options="customFormOptions">...</form>

disable form completly

<form disable-form="{{booeleanVar}}">...</form>

check for matching passwords via ngFabMatch-directive

<form>
  <input type="password" ng-model="realPassword" required>
  <input type="password" ng-model="pwRepeat" ng-fab-match="realPassword" required>
</form>

Validate by expression via ngFabEnsureExpression-directive

<form>
  <input type="text" ng-fab-ensure-expression="testModel=='test'" ng-model="testModel" required>
</form>

special validations for special cases (e.g. ng-pattern)

Sometimes you might want to have another text for a specific context. Special validation-messages like this are easily added like this:

<input type="text"
  ng-model="my-model"
  required
  ng-pattern="/abcdefg/"
  validation-msg-pattern="Not abcdefg :(">

default validations and creating your own validation template

ng-fab-form comes with a reasonable default validation template, which is used for every form element with ng-model set. But you can easily create your own if you don't like the either the messages or the markup! In your own template you can use any attribute and directive, as you would with vanilla angular. In addition the input-element attributes are available for you convenience, too!

This is what the default validation template looks like:

<!-- Default Validation Template -->
<div class="validation"
     ng-show="attrs.required===''|| attrs.required">
     <!-- Show errors for invalid fields, when it has been either focused,
      has been changed or the user tried to submit the form without success
      (requires the setDirtyOnSubmit-option to be set-->
    <ul class="list-unstyled validation-errors"
        ng-show="field.$invalid && (field.$touched || field.$dirty || form.$triedSubmit)"
        ng-messages="field.$error">
        <li ng-message="required">This field is required</li>
        <li ng-message="password">Please enter a valid password</li>
        <li ng-message="email">Please enter a valid e-mail</li>
        <li ng-message="pattern">Invalid input format</li>
        <li ng-message="date">Please enter a valid date</li>
        <li ng-message="time">Please enter a valid time</li>
        <li ng-message="datetime">Please enter a valid date and time</li>
        <li ng-message="datetime-local">Please enter a valid date and time</li>
        <li ng-message="number">This field must be numeric</li>
        <li ng-message="color">Please enter a valid color</li>
        <li ng-message="range">Please enter a valid range</li>
        <li ng-message="month">Please enter a valid month</li>
        <li ng-message="url">Please enter a valid URL</li>
        <li ng-message="file">Invalid file</li>

        <!-- ng-fab-form provides you with access to the
        input-element-attributes, allowing you to display their values
        inside of the message-->
        <li ng-message="minlength">Please use at least {{ attrs.minlength }} characters</li>
        <li ng-message="maxlength">Please do not exceed {{ attrs.maxlength }} characters</li>

        <li ng-if="attrs.type === 'time' "
            ng-message="min">The time provided should be no earlier than {{ attrs.min |date: 'HH:MM' }}
        </li>
        <li ng-message="ngFabMatch">The {{ attrs.type ==='password'? 'passwords' : 'values' }} should match</li>


        <!-- you can use ng-if or ng-show for more advanced
        error messages -->
        <li ng-if="attrs.type === 'time' "
            ng-message="min">The time provided should after {{ attrs.min |date: 'HH:MM' }}
        </li>
        <li ng-message="max"
            ng-if="attrs.type === 'time' ">The time provided should be before {{attrs.max |date: 'HH:MM'}}
        </li>
        <li ng-message="min"
            ng-if="attrs.type === 'date' ">The date provided should be after {{attrs.min
          |date:'dd.MM.yy'}}
          </li>
        <li ng-message="max"
            ng-if="attrs.type === 'date' ">The date provided should be before {{attrs.max |date: 'dd.MM.yy'}}
        </li>
        <li ng-message="min"
            ng-if="attrs.type === 'number' ">The number provided should be at least {{attrs.min}}
          </li>
        <li ng-message="max"
            ng-if="attrs.type === 'number' ">The number provided should be at max {{attrs.max}}
        </li>
    </ul>
    <!-- It is also possible to show a success element
    using the standard form syntax -->
    <div class="validation-success"
         ng-show="field.$valid && !field.$invalid">
    </div>
</div>

To load you own validations simply set the template url in your configuration:

angular.module('exampleApp', [
    'ngFabForm'
])
    .config(function (ngFabFormProvider)
    {
        ngFabFormProvider.extendConfig({
            validationsTemplate : 'path/to/your-fabulous-validation-template.html'
        });
    });

create and share

You can use this plunkr as base for your fabulous creation! Think you created something useful? Then share it!!! Either provide a pull-request or leave a comment on the projects public page.

If you provide a pull-reqest, please use a feature-branch. The commit should usually contain two files: A html template and a scss-file.

resettable forms

There are two ways to reset your form. The first one requires you to use the 'contallerAs'-syntax to access the form controller:

<div ng-controller="myCtrl as ctrl">
  <form name="ctrl.myForm">
    <input type="text"
      ng-model="my-model"
      required>
    <button type="button"
      ng-click="resetForm()">
      Reset the form!
    </button>
  </form>
</div>
myMod.controller('myCtrl', function(){
    var vm = this;
    vm.resetForm = function(){
        // this resets the form without clearing the inputs
        vm.myForm.$resetForm();
        
        // this resets the form with setting all ng-model 
        // values in it to undefined
        vm.myForm.$resetForm(true);
    }
});

The second one uses the 'ng-fab-reset-form-on' directive:

<form>
  <input type="text"
    ng-model="my-model"
    required>
  <button type="button"
    ng-fab-reset-form-on>
    Reset the form!
  </button>
</form>

As per default the button (or any other element) is triggered on click. If you need something else you can provide those by setting a value. If you need multiple events, separate them by a space:

<button type="button"
  ng-fab-reset-form-on="touchstart my-custom-event-on-this-element">
  Reset the form!
</button>

Another default is to reset the 'ngModel' value of all form inputs to 'undefined'. You can prevent this behaviour by using the do-not-clear-inputs attribute:

<button type="button"
  ng-fab-reset-form-on
  do-not-clear-inputs>
  Reset the form, but leave the inputs be!
</button>

advanced configurations

adjust insertion function of validation messages

You can edit where and how the messages are inserted in relation to their corresponding form-element:

angular.module('exampleApp', [
    'ngFabForm',
    'ngAnimate'
])
    .config(function (ngFabFormProvider)
    {
        var customInsertFn = function (compiledAlert, el, attrs)
            {
                // insert after or after parent if checkbox or radio
                if (attrs.type === 'checkbox' || attrs.type === 'radio') {
                    el.parent().after(compiledAlert);
                } else {
                    el.after(compiledAlert);
                }
            };
        ngFabFormProvider.setInsertErrorTplFn(customInsertFn);
    });

use a custom scroll-to handler

You can change the scroll animation-handler to one of your liking:

angular.module('exampleApp', [
    'ngFabForm',
    'ngAnimate'
])
    .config(function (ngFabFormProvider)
    {
        var customScrollToFn = function (targetElement, duration, scrollOffset)
            {
               targetElement.scrollIntoView(true);
               targetElement.focus();
            };
        ngFabFormProvider.setScrollToFn(customScrollToFn);
    });

A good starting point for you might be the default function which can be found inside of the ngFabFormProvider.

adding your own validators (or overwriting existing ones)

The default validations for email, url and number fields are not always what you want. ng-fab-form provides you with an api to add your own or to overwrite the existing ones:

angular.module('exampleApp', [
'ngFabForm',
])
.config(function (ngFabFormProvider)
{
  var customValidatorFn = function (ngModelCtrl, attrs)
  {
    var regex = /www.only-awesome-urls.tu/;
    if (attrs.type === 'url') {
      ngModelCtrl.$validators.url = function (value)
      {
        return ngModelCtrl.$isEmpty(value) || regex.test(value);
      };
    }
  };
  ngFabFormProvider.setCustomValidatorsFn(customValidatorFn);
});

deactivate ng-fab-form globally and only use it via the ng-fab-form-directive

If needed, you can configure ng-fab-form to be only used by the ng-fab-form-directive.

angular.module('exampleApp', [
    'ngFabForm'
])
    .config(function (ngFabFormProvider)
    {
        ngFabFormProvider.extendConfig({
            globalFabFormDisable: true
        });
    });

Then in your template, you just add ng-fab-form to the forms in question:

<form ng-fab-form></form>

There is a drawback: This won't work together with the setAsteriskForLabel-option.

❤ contribute ❤

I'm happy for any issue or feature request, you might encounter or want to have. Even a one liner is better, than no feedback at all. Pull requests are also highly welcome. Just fork the repository, clone it and run grunt serve for development. Another important factor is the number of developers using and thus testing ng-fab-form. Tell your fellow programmers, say that you use it on ng-modules, tweet or even blog about it.

ng-fab-form is published under the The GNU Lesser General Public License V2.1.

(possible) fabulous future features

ng-fab-form's People

Contributors

adrianhuna avatar barefootdeveloper avatar jacqueslareau avatar johannesjo avatar nileshpatil-dev avatar sajidali avatar waffle-iron avatar wgorder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng-fab-form's Issues

Getting Injector Error

Hi,

I am getting this error after adding 'ngFabForm' to my module dependency

fabform
Error: [$injector:unpr] Unknown provider: $templateRequestProvider <- $templateRequest <- ngFabFormDirective <- inputDirective

why is this so.

Please guide

Validate on blur (and maybe using ng-model-options?)

First of all, thanks for your great tool.

My issue is that the fields validate immediately, an option to debounce or validate on blur would be helpful.

I tried to use ng-model-options="{ updateOn: blur }" but didn't work.

This is particularly problematic when async validating at "register user" time, when I need to go to the server to make sure the user doesn't exist.

The program then issues several http requests all of them returning inexistent user (since it's an incomplete email address) and the last potentially saying that the user already exist.

I would love to create a pull request since I'd rather collaborate instead of nag, but my experience in JS and angular aren't enough.
Thanks in advance.

Miguel Delgado

Sourcemap file is referenced but not included in dist

Super minor issue:

In the distributed js files the map file is referenced but not included so you'll get a 404 if you open developer tools while on a page that uses it.

//# sourceMappingURL=ng-fab-form.min.js.map

I'm sure it's a quick tweak in the gulpfile that I can look at when I get a chance. Although it might honestly be better to just not output the sourcemappingurl in the distributed files.

Add Support for Dot Notation in Form Names

If you attempt to name a form with dot notation

you will get errors like

Cannot read property 'ctrl_control' of undefined

This is being caused by the way the form is being access on the scope.

I fixed this in pull request #19

[This has been pulled in and completed for anyone that finds this]

Add a way to wait for form controller to initialize

I must be doing something wrong. I have a component that looks like this:

      <div class="form-group">
          <label for="{{formName+index}}" class="col-md-4 control-label">{{label}}</label>
          <div class="col-md-8">
              <textarea ng-minlength="minLength" ng-readonly="readOnly" ng-maxlength="maxLength" ng-model="inputText" ng-required="required" id="{{formName+index}}" rows="{{rows}}" class="form-control" placeholder="{{placeholder}}"/>
              <p class='help-block'>{{description}}</p>
          </div>
      </div>

For whatever reason for textAreas the validation template for ng-fab-form is not being appended to text area elements. Do you see something wrong with the above? Any idea where I should look. It is appended properly to inputs.

Does not work with dynamic data

Suppose i dynamically add element by javascript;

i cant see validation error
here is code snipped

/@description:to upload video to aws and execute the function/
app.directive('select, function ($parse,$compile) {
return {
link: function (scope, elm, attr, ngModelCtrl) {

        var html = "<input type='text' class='uiselectclass' ng-model=" + attr.ngModel + " required/>"
        var angualarHtml = $compile(html)(scope);
        elm.after(angualarHtml)
    }
};

});

Duplicate Form warning

Can we have a way to disable this via config?

Currently it triggers when I have a form that is conditionally shown. Even though it is not a duplicate form it is still printing the message. Note it does not show the message initially but if the form is removed and then re-added to the dom it triggers the warning.

How to set form pristine?

On a successful submit I have need to reset the form e.g.

$scope.formData = {}
$scope.contactForm.$setPristine()

Doing this does reset the form fields but they are all showing the indicators. Perhaps I missed something, what is the correct way to do this?

Consider using the non-minified version in bower-main

The reason being many front end developers use gulp, grunt or a similar build tool which does this for you. If you are not using these build tools you are probably not using bower either, or you can include the minified version if you want. Having it already minified messes up these tools.

Also if your like me I like to serve the non-minified version during development. I only minify on production build. What gets served is what is defined in the main of the bower file.

Also that is the official recommendation, see here:

See bower/bower#393

Current spec description:

The primary acting files necessary to use your package. While Bower does not directly use these files, they are listed with the commands bower list map and bower list --sources, so they can be used by build tools. Do not include minified files. Files should not be versioned (Bad: package.1.1.0.js; Good: package.js).

Support assigning configuration to individual form

Hi,

The idea of this module is just brilliant.

Currently there is a global configuration object via ngFabFormProvider. It's a good place for default settings.

But in some cases, one particular form may need to override the global configuration.

What do you think?

Best wishes,
Oliver

Implement a CHANGELOG.MD

Hi @johannesjo,

Thanks for all your hard work! It would be brilliant if you could provide a CHANGELOG so that it is easy for us to see when new features are added or bugs fixed.

It is currently really hard to know when/whether to update.

Many thanks,

James

Using require to load custom template

Hi,

I'm working on a project where I'm using browserify and ng-fab-form and a custom template. I'm using the following syntax:

ngFabFormProvider.extendConfig({
    validationsTemplate : require('./customTemplate.html')
});

and I get the following error:

Error: [$compile:tpload] Failed to load template: <div ng-messages="field.$error"
     class="validation has-error">
    <div class="list-unstyled validation-errors help-block"
        ng-show="field.$invalid && (field.$touched || field.$dirty || form.$triedSubmit)">
        <div ng-message="required">{{'VALIDATION-MESSAGES.REQUIRED' | translate}}</div>
        <div ng-message="password">{{'VALIDATION-MESSAGES.INVALID-PASSWORD' | translate}}</div>
        <div ng-message="email">{{'VALIDATION-MESSAGES.INVALID-EMAIL' | translate}}</div>
        <div ng-message="pattern">{{'VALIDATION-MESSAGES.DOES-NOT-MEET-REQUIREMENTS' | translate}}</div>
        <div ng-message="date">{{'VALIDATION-MESSAGES.INVALID-DATE' | translate}}</div>
        <div ng-message="time">{{'VALIDATION-MESSAGES.INVALID-TIME' | translate}}</div>
        <div ng-message="datetime">{{'VALIDATION-MESSAGES.INVALID-DATE-TIME' | translate}}</div>
        <div ng-message="datetime-local">{{'VALIDATION-MESSAGES.INVALID-LOCAL-DATE-TIME' | translate}}</div>
        <div ng-message="number">{{'VALIDATION-MESSAGES.INVALID-NUMBER' | translate}}</div>
        <div ng-message="color">{{'VALIDATION-MESSAGES.INVALID-COLOR' | translate}}</div>
        <div ng-message="range">{{'VALIDATION-MESSAGES.INVALID-RANGE' | translate}}</div>
        <div ng-message="month">{{'VALIDATION-MESSAGES.INVALID-MONTH' | translate}}</div>
        <div ng-message="url">{{'VALIDATION-MESSAGES.INVALID-URL' | translate}}</div>
        <div ng-message="file">{{'VALIDATION-MESSAGES.INVALID-FILE' | translate}}</div>

        <div ng-message="minlength">{{'VALIDATION-MESSAGES.DOES-NOT-MEET-MIN-LENGTH' | translate}}</div>
        <div ng-message="maxlength">{{'VALIDATION-MESSAGES.DOES-NOT-MEET-MAX-LENGTH' | translate}}</div>

        <div ng-if="attrs.type == 'time' "
            ng-message="min">{{'VALIDATION-MESSAGES.DOES-NOT-MEET-MIN-TIME' | translate}}</div>
        <div ng-message="max"
            ng-if="attrs.type == 'time' ">{{'VALIDATION-MESSAGES.DOES-NOT-MEET-MAX-TIME' | translate}}</div>
        <div ng-message="min"
            ng-if="attrs.type == 'date' ">{{'VALIDATION-MESSAGES.DOES-NOT-MEET-MAX-DATE' | translate}}</div>
        <div ng-message="max"
            ng-if="attrs.type == 'date' ">{{'VALIDATION-MESSAGES.DOES-NOT-MEET-MAX-DATE' | translate}}</div>
    </div>
    <div class="validation-success"
         ng-show="field.$valid && !field.$invalid">
    </div>
</div>

Any ideas on how to fix this?

Thanks,

Adrian

Javascript error if some input isn't inside a form.

Hey, I have no much experience programming front-end code, so maybe this is my mistake and not really an issue in your framework, but i'm reporting, so you can analyse it better. I'm programming an application using jhipster and for an entitie list screen the elements are not declared inside a

(this only happens on the editing modal screen) and on my list screen I had put a search input, which is causing a javascript error when using ng-fab-form, here is the stacktrace:

TypeError: Cannot read property '$name' of null
at http://0.0.0.0:9000/bower_components/ng-fab-form/dist/ng-fab-form.min.js:1:4506
at invokeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:8211:9)
at nodeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:7720:11)
at compositeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:7073:13)
at compositeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:7076:13)
at compositeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:7076:13)
at compositeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:7076:13)
at publicLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:6952:30)
at link (http://0.0.0.0:9000/bower_components/angular-route/angular-route.js:989:7)
at invokeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:8211:9)

angular.js:11592 TypeError: Cannot read property 'ngFabFormConfig' of null
at http://0.0.0.0:9000/bower_components/ng-fab-form/dist/ng-fab-form.min.js:1:4438
at http://0.0.0.0:9000/bower_components/angular/angular.js:16203:28
at completeOutstandingRequest (http://0.0.0.0:9000/bower_components/angular/angular.js:4900:10)
at http://0.0.0.0:9000/bower_components/angular/angular.js:5280:7

The problem is that your framework is modifying all the input elements, and for some reason it uses the parent form name, when there is an input outside a form element is raised this error. Is not a big issue, since I resolved this by just wrapping this search input with a "form" element, but I think it may be not mandatory that every input is inside a form. Please let me know if i'm doing something wrong which may causing this issue.

screenshot from 2014-12-16 14 07 18

Fix animations for mobile

The animations tend to expand the screen size during animation on mobile (seen using default chrome on my nexus 6). This causes the right side to grow, which looks funny.

i18n support

Hi,

Does your module support or plan to support i18n?

ngAnnotate() with ng-strict-di

Thanks for providing the uniminified version in bower main! I have one more request. I use ng-strict-di="true" on my application, and when I pull in the unminified version it is throwing errors. Do you suppose you could add the ngAnnotate() build step before producing the unminified js file as well and not just as a part of the uglify step?

That way both the uniminified and minified versions would pass the ng-strict checks.

Passwords

Looks nice I am about to try it out. Looking at it would be neat if could support matching password validation (common scenario on registration forms)..

Also some of the English needs to be touched up in the default messages. Looks very nice though, thank you.

make a un-minified version in dist

Hi, I'm currently trying out this module.

Is it possible to have the un-minified version in the dist folder? I'd like to use it for dev and minify it myself.

Will try this module out and give feedback.

Thanks!

Question about customFormOptions

When I supply a form with custom form options via the ng-fab-form-options tag it does use those options, but my expectation is that it would use it only for that form with that attribute set. It appears that it does not revert back to using the defaults (or in my case a customized version that I specified using ngFabFormProvider.extendConfig when that attribute is not present. Is this the intended behavior?

Async Validation

Hello
I am currently trying ng-fab-form. And i have troubles with "unique validation".
For exemple, if an user try to register with an already used email adress. He ll cross the frontend validation but not the backend.

It is this backend error that i want to report on the email field's error message.

Can you explain me a way to achieve that.

Thanks.

Btw : Great job for this module

Add $resetForm function

which includes
$setPristine()
$setUntouched()
$triedSubmit = false

clearing of all input-elements.

Directive support that adds validation

A way to add "a loading bar" for the state $pending
and also include the validation for SSN in the ng-fab-form that is returned by deferred.Resolve()
(i dont seem to be able to figure out how to input in the description!
'
'
Checking Availability . . .


This SSN already exist in the database


<script type="text/javascript"> ``` (function () { var addEmployeeModule = angular.module("addEmployeeModule", ["kendo.directives", 'ngMessages', 'ngAnimate', 'ngFabForm']); addEmployeeModule.config(function (ngFabFormProvider) { ngFabFormProvider.extendConfig({ setAsteriskForRequiredLabel: true }); }); addEmployeeModule.controller("AddEmployee", function ($scope, ngFabForm) { $scope.formOpt = ngFabForm.config; $scope.validationMessages = ngFabForm.validationMessages; $scope.advancedValidations = ngFabForm.advancedValidations; }); addEmployeeModule.directive('uniqueSocial', function (isUsernameAvailable) { return { restrict: 'A', require: 'ngModel', link: function ($scope, element, attrs, ngModel) { //The reason we use unique on
This is taken
//is because we set a ngModel async validator called unique ngModel.$asyncValidators.unique = isUsernameAvailable; } } }); addEmployeeModule.factory('isUsernameAvailable', function ($q, $http) { return function (ssn) { console.log(ssn); // You may be wondering where ssn this comes from. That is: // var deferred = $q.defer(); //Check is the ssn has not been entered at all before beggining to validate if (angular.isUndefined(ssn) || ssn === '') { deferred.resolve(); } else { $q.all([$http.post('/api/IsSocialSecurityAvailable/' + ssn)]).then(function (data) { console.log(data); deferred.reject(data); }, function (error) { console.log(error); deferred.resolve(error); }); } return deferred.promise; } }); }()); ``` </script>

Ng-click support

How can we trigger validation by ng-click instead of ng-submit?

Question - Validation success class

Hi. I like the effect you have on your demo, with the green checkmark. However I noticed that if you hide and show the form using ng-if or show/hide etc. That the validation-success effect is shown briefly. Do you know of a way to prevent that?

Success Validation shows before field has had focus

The green checkmark shows right away on a field that does not have validation constraints e.g. is not required. I would say that it should follow the same rules as error messages and not show until the form is submitted, or has received focus

Ability to use bootstrap validation classes when displaying errors

Hi,

I've used the customization feature to specify where to add error messaging:

.config(function (ngFabFormProvider) {
var customInsertFn = function (compiledAlert, el, attrs) {
el.parent().after(compiledAlert);
};

    ngFabFormProvider.setInsertErrorTplFn(customInsertFn);
})

But now I'm looking for a way to add and remove bootstrap validation classes to the parent element.

With default value for required field, it shows validation icon without form being submitted or dirty

When there is default value for a required field, the field show validation CHECK icon, but the form is not yet submitted or dirty.

check this plunker example
http://plnkr.co/edit/9sEXQB?p=preview

$scope.formData.requiredMaxlength is populated with 'ok' value, and the form shows only this field as valid.

Can it be fixed, that form only shows valid icons and invalid messages upon field modifications or on form submit?

P.S In actual scenario, my form is being populated with ajax response.

match directive conflicts with ui-boostrap

Error: [$compile:multidir] Multiple directives [match, typeaheadMatch] asking for new/isolated scope on:


http://errors.angularjs.org/1.3.14/$compile/multidir?p0=match&p1=typeaheadM…%3D%22match%22%20query%3D%22query%22%20template-url%3D%22templateUrl%22%3E

Apparently angular ui-bootstrap uses a match directive. Can we prefix this one to avoid this. (match password directive)

I had never had this happen before, but apparently it has come up :)
http://stackoverflow.com/questions/25777047/error-trying-to-add-angularjs-bootstrap-typeahead-into-custom-directive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.