Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How it works? #18

Closed
e-oz opened this issue Mar 21, 2015 · 6 comments
Closed

How it works? #18

e-oz opened this issue Mar 21, 2015 · 6 comments
Labels

Comments

@e-oz
Copy link

e-oz commented Mar 21, 2015

Hello!
Please give 1 small (in code) to show how it works. Is it about building forms from JS (as formly, JSX) or it's about validation (analogue of ng-messages) or something else?

@mchapman
Copy link
Contributor

Hi!

At the moment there is very little visible, but the angular 1 adaptor is the best example. The idea is that it handles validation (at least) in the core, and form generation in adaptors (probably one adaptor set for each combination of CSS framework / JS framework). So far most of work has been on the core.

@bvaughn
Copy link
Owner

bvaughn commented Mar 21, 2015

Hey @Jamm,

This library is intended to be the base used by other, more framework-specific ports. (We plan on creating an Angular 2 port first, but also a web components port, React, perhaps Angular 1, etc.) It's kind of a work in progress at the moment, but here's how things are setup at a high level:

  1. Create an instance of formsjs.Form. (Optionally pass it a custom formsjs.Strings object if you want to override its default error messages).
  2. Set the formsjs.Form.submitFunction property. This should be a (Service?) function that receives a data parameter and returns a Promise to be resolved/rejected based on the server response from submitting your form data.
  3. Parameter-inject the instance of formsjs.Form into input components/directives so that they can call formsjs.Form.registerAttribute().
  4. formsjs.Form.registerAttribute() returns a ``formsjs.AttributeMetadataobject that will be the shared point of communication between the directive/component and the parentformsjs.Form` instance. (It's what the component/directive should bind to.)
  5. Call ``formsjs.AttributeMetadata.validate()any time a field/model changes. It will update important bindable properties (likeerrorMessages`) which the directive should be displaying.
  6. Call formsjs.Form. submitIfValid() in order to submit the form. (Note that the form will only submit if it's valid, otherwise the Promise this method returns will be rejected.)

@bvaughn
Copy link
Owner

bvaughn commented Mar 21, 2015

We only very recently started work on this, after some debate and discussion (see here) on how to approach the problem. Our main goal was to combine efforts into 1, powerful/flexible form validation library that we could create lightweight adapters on top of rather than all create our own individual libraries. We'd love to hear your input if you'd be interested in helping! :)

@e-oz
Copy link
Author

e-oz commented Mar 21, 2015

@bvaughn so because of step 3, we will need to write line of JS for each controller we have in form?

@bvaughn
Copy link
Owner

bvaughn commented Mar 21, 2015

Not exactly. The above steps are kind of a guideline for the adapters we're building. So for instance, when we create a forms-js-angular-2 adapter- that will be a really lightweight library that just connects Forms JS classes to Angular's injector and exposes a couple of directives for creating forms via markup. Steps 1-6 are kind of how these directives will hook into Forms JS for validation.

For a user to use Forms JS, it will be much simpler. They'll either pass a JSON schema or a form validation schema. (More info on this discussion thread and this drive doc.)

Its also fairly similar to how my current form library, formFor works:
http://bvaughn.github.io/angular-form-for/#/demo/validation-types

(I only mention formFor because its documentation is a little prettier and easier to read than our discussion thread.)

@bvaughn
Copy link
Owner

bvaughn commented Mar 24, 2015

I believe this question's been answered sufficiently as far as the issue-tracker goes. If you'd like to chat more about this effort, @Jamm, I'd be happy to hop on Gitter or Hangout with you and discuss. :)

@bvaughn bvaughn closed this as completed Mar 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants