json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

Various Enhancements: Enhanced access to actual array element form defs, Dynamic change of other form elements from change handler and more #585

Open roberttaylortech opened 9 years ago

roberttaylortech commented 9 years ago

I have whole queue of enhancements/ideas/design suggestions queue up from working with ASF for a good while. I've read enough of the source code to pretty familiar, but not quite familiar enough with enough time to actually try to hack the changes in how I'd like to see them... I think I'll just suggest in example code...

{
    key: "modules[].activities",
    add: 'Add activity'

    ,items: [

        {
//putting this element first just in this example
          key:"modules[].activities[].fullFilePath"
        }, 
        {
            key:'modules[].activities[].srcFolderPath',
            onChange:function(modelValue, form, schemaFormSystem, rootForm)
            {

                // HMMM... I *really* need to access the form element for "modules[].activities[].fullFilePath",
                // more specifically for "modules[n].activities[n].fullFilePath"
                // because I need to change something -- like the titleMap for modules[n].activities[n].fullFilePath and JUST modules[n].activities[n].fullFilePath
                // that correspond to the n-th item that this field corresponds to

                var $injector = angular.injector(['ng']);

                $injector.inject(['$http', function($http)
                {
                    $http.get('/getFileListingForFolderByFolderName/' + modelValue)
                        .then(function(resp){

                        var data = resp.data;
                        var PathOfCurrentFormDef = schemaFormSystem.getPathForFormDefintion(form)
                        // PathOfCurrentFormEl is string "modules[2].activities[1].srcFolderPath'"

                        var BasePathForFormDef = schemaFormSystem.getBasePathForFormDefintion(form)
                        // BasePathForFormDef is string "modules[2].activities[1]"

                        var myFormDefinitionToUpdatePath =  BasePathForFormDef + '.fullFilePath'

                        var myFormDefinitionToUpdate 
                                = schemaFormSystem.getFormDefinitionByPath(rootForm, myFormDefinitionToUpdatePath)

                        myFormDefinitionToUpdate.titleMap = _.map(data.FileListing), function(filename){
                            return {name:filename, value:filename}

                        })

                        schemaFormSystem.redraw(myFormDefinitionToUpdate);

                    })

                })

            }
        },

    ]
}   

So... quick summary and perspective on a few of the needs/suggestions etc:

Oh Btw.. I might suggest start "flattening" the args to onChange. Rather than: onChange:function(modelValue, form, schemaFormSystem, rootForm)... onChange:function(changeContext) where:

 changeContext = {
    modelValue:modelValue,
    ngModel: ngModelForChangingFormDef
    form: changingFormDef,
   schemaFormSys : schemaFormSysInstance
   rootForm: rootLevelFormFor the changingFormDef 
 }

Just give us more stuff to roll our own/hack with! And a single arg is much more future proof ;)

It's kind an urgent need for some few parts of this somehow, someway. Maybe with some guidance on how to implement ( or some extra time on my hands soon!) I could hack at it. Any Quick Ideas? Maybe for the "Enhanced access to actual array element form defs" component of this.... or the limited redraw aspect?

I'll likely add more comments/perspective to this post later. Or discussion.Time to break for now.

Anthropic commented 9 years ago

"Need form elements to be able for update other form elements from within itself." I've done this with my add on (external-options the latest version in git not bower...), take a look at how it works, not too hard to load new titleMaps from a server dynamically. I will improve on this soon and was considering making a separate add on to assist with a pure titlemap load without it being specifically select related.

Anthropic commented 8 years ago

@souluniversal it would help if your suggestions were in separate issues so they can each be considered on their own merit.

FYI the new builder does pre-render the form and has made performance improvements and is expected to be enhanced to do partial updates in future.

roberttaylortech commented 8 years ago

Marcel, thanks. I actually hackishly implemented a good bit of it. I don't really have time to clean it up or do a pull request etc -- would you (anyone?) possibly want to coordinate to have a look and consider the changes directly with me?

roberttaylortech commented 8 years ago

Btw, when I say hackishly, I would call it 85% quality level. Maybe higher, we'll see!

Anthropic commented 7 years ago

@souluniversal does this offer still stand, I think I understand the code a lot better now and could potentially implement some things. Some of the items are already planned, like a rules engine that can update properties of multiple fields based on conditions. Have you seen the new alphas?