formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

Using fieldGroup it has problem with custom select box #723

Closed mcassani closed 7 years ago

mcassani commented 7 years ago

When I use a fieldGroup with three custom select boxes (I did a specific wrapper to put in the same row the label and the form-control). When the select boxes use different properties in the "as" part of the ngOptions, only the select boxes that have the same property of the first select box of the group work correctly. All the others display "undefined". In my example I have 3 selects, the 1st and de 3rd use the 'name' property but the 2nd use 'description'. The 1st and 3rd are running perfectly, but the other doesn't show the content and it shows 'undefined'.

JS Bin link: http://jsbin.com/losevat/edit?html,js,output

Sorry for my bad english.

Jaygiri commented 7 years ago

As per your bin, there is an error on Gender service. You are using "description" instead of "name".

Here is corrected bin: http://jsbin.com/bejazidaqe/edit?js,output

mcassani commented 7 years ago

@Jaygiri thank you for your answer but is the problem.. I need to use "description" instead of "name". If I use "name" in the first combobox yes or yes I have to use "name" property in the rest and I need use different.

Jaygiri commented 7 years ago

@mcassani sorry I miss-understood the issue. Here is the solution http://jsbin.com/kibaboluhi/2/edit?js,output

Looks like extend is failing for select defaultOptions

@kentongray it would be good learning if you explain what is the actual issue here with extend.

Jaygiri commented 7 years ago

@mcassani I have found more appropriate solution, using angular.extend

app.run(function(formlyConfig) {
    var selectType = formlyConfig.getType('select');
    formlyConfig.setType(angular.extend({}, selectType, {
      name: 'horizontalSelect',
      wrapper: ['horizontalBootstrapLabel', 'bootstrapHasError']
    }));
  });

http://jsbin.com/nuguzeqozi/1/edit?js,console,output

mcassani commented 7 years ago

@Jaygiri thank you so much! I'm using it and it works perfectly