json-schema-form / json-schema-builder

The JSON Schema form builder
MIT License
70 stars 16 forks source link

Defining the "Basic Usage" #3

Open ThomasPe opened 8 years ago

ThomasPe commented 8 years ago

So we can work towards a common goal I'd like to discuss how exactly the Json Schema Builder should be used / called / included. I created a small "Basic Usage" example based on the Angular Schema Form Example. As I see it, it should be enough to just have a $scope.schema and a $scope.form (and an optional $scope.options) object for passing & receiving data, right?

Here's what I think it could look like (from my fork)

First, expose your (existing) schema and form to the $scope.

angular.module('myModule', ['schemaFormBuilder'])
       .controller('FormBuilderController', function($scope) {
  // JSON Schema
  // add an existing schema to edit it
  // or leave blank to create a new form
  $scope.schema = {};

  // Schema Form Defintion
  // add an existing form definition for editing
  // or leave blank to create a new form
  $scope.form = [];

});

Then load them into the Schema Form Builder using the sfbSchema and sfbForm directives.

<div ng-controller="FormBuilderController">
    <div sfb-schema="schema" sfb-form="form"></form>
</div>

Thoughts?

nicklasb commented 8 years ago

Well, yeah, something like that would be the usage, I suppose. As close as the normal ASF usage as possible.

Have you looked closer to see if it easy to break out a directive from the application?

nicklasb commented 8 years ago

Took a quick look, and the code seems really nice, it should be pretty easy to break that out.

ThomasPe commented 8 years ago

I'm currently working on that. There's some functionality in there that does not belong into the library IMHO, like saving forms or notifying the user of changes (locker, growl). But the code is well-structured, so it's certainly possible. I'll have to read up on some angular convetions & best practices first, though.

nicklasb commented 8 years ago

Please do, it would be a killer feature if you could get that done.

ThomasPe commented 8 years ago

I'm gonna need this for my masters thesis, so eventually I'll have to ;-)

nicklasb commented 8 years ago

Good choice. :-)

Anthropic commented 8 years ago

I'm partial to: https://github.com/johnpapa/angular-styleguide The material repo also has a jscs file that follows Google code guide with minor differences, but I haven't looked into the builder enough to know how appropriate that is, however it would be nice to follow the same guides across all js implementations within the org. That's my 2c :)

ThomasPe commented 8 years ago

Thanks, I'll give it a look and try to abide by it.