MacKentoch / easyFormGenerator

create amazing forms without coding : form editor based on angular formly
http://mackentoch.github.io/easyFormGenerator/
MIT License
254 stars 116 forks source link

Allow to add list of preconfigured fields #17

Open gentledepp opened 8 years ago

gentledepp commented 8 years ago

Hi!

First of all - this form generator looks great. However, in order to be able to use it, we need to be able to specify our own list of fields and those fields are preconfigured and can only be added but not changed.

The reason behind this, that we have an application that allows to add additional fields to existing entities. Say we have a task with the fields "AssignedUser, Title, DueDate" and then the user adds a custom field "Category" This category field is defined elsewhere in our application as an enumeration of categories. So basically, the user should now be able to place the field on the form and edit some of its visual properties like being displayed as a dropdown or a radio button list.

Moreover, we'd like to disable all of your barebone fields.

Would that be possible?

MacKentoch commented 8 years ago

Hi @gentledepp,

Thank you for your nice feedback.

If I correctly sum up your request (feel free to correct me if I'm wrong), it would be nice to :

1- preload existing form

//easy form generator :
<eda-step-way-easy-form-gen     
      eda-easy-form-generator-model="_MODEL_"
      eda-save-form-event="_SAVE_FUNCTION_">
</eda-step-way-easy-form-gen>
//easy form viewer = just render a form : 
<eda-easy-form-viewer
        eda-easy-form-viewer-data-model="demoCtrl.dataModel"
        eda-easy-form-viewer-easy-form-generator-fields-model="demoCtrl.fieldsModel"

        eda-easy-form-viewer-submit-button-text="{{demoCtrl.submitButtonText}}"
        eda-easy-form-viewer-cancel-button-text="{{demoCtrl.cancelButtonText}}"

        eda-easy-form-viewer-submit-form-event="demoCtrl.submitFormEvent(dataModelSubmitted)"
        eda-easy-form-viewer-cancel-form-event="demoCtrl.cancelFormEvent()">    
</eda-easy-form-viewer>

2- but loaded form should have locked fields

But right now it is not implemented...

BUT it may not be that hard to satisfy your needs since it seems like it is just a matter of new custom formly control

A control is basically some kind directive and you can create unlimited custom formly controls. An exemple : here.

    // here is this custom formly multi input control (JS part) :
    formlyConfigProvider.setType({
      name: 'multiInput',
      templateUrl: 'multiInput.html', //I don't copy html but you check the template in JSBIN in the upper link 
      defaultOptions: {
        noFormControl: true,
        wrapper: ['bootstrapLabel', 'bootstrapHasError'],
        templateOptions: {
          inputOptions: {
            wrapper: null
          }
        }
      },
      controller: /* @ngInject */ function($scope) {
        $scope.copyItemOptions = copyItemOptions;

        function copyItemOptions() {
          return angular.copy($scope.to.inputOptions);
        }
      }
    });

I would have to add this new template to easy form generator if it were exactly the one you needed.

Now the most difficult part may be to :

How does it sound like for you? It would be nice I think.

gentledepp commented 8 years ago

Hey, thanks for the quick response!

But basically the answer is "no, this is not what I meant" - I apologize.

Your angular module basically provides a way to create complete forms that consist of

In our case, fields are defined separately. You can think of it like a CMS. You have some built-in content types that consist of a set of fields. Those fields cannot be removed from their content types, but you can add additional fields. As an example, you can look at the documentation of Orchard CMS: http://docs.orchardproject.net/Documentation/Creating-custom-content-types

So basically the user has the ability to add additional custom fields to one of the predefined content types. Those fields define their data type, their default display type, their validation logic, etc.)

Now we need to somehow give the user the ability to add those self-created fields to the existing built in content types forms.

So what we'd basically like to do is to provide your form generator with a an array of field objects that are already completely configured (those can be angular-formly fields) The user can now only

As this is merely a reduction of functionality (i.e. locked-down field definitions) I hoped it would be quite easy to implement. :-|

Tell me what you think!

MacKentoch commented 8 years ago

Sorry for my misunderstanding.

Don't worry and let me think about it.