1

I have 3 available options in my formly form select right at the beginning. An empty option (I want to keep regardless if an options has been selected), 'Advance' and 'Arrears'. Once I select an option, the empty one disappears. I'm trying this to keep it but it doesn't work.

{
    className: 'col-xs-3',
    key: 'advanceOrArrears',
    type: 'select2',
    templateOptions: {
        label: 'Advance or Arrears',
        required: true,
        options: [
            {name: 'Advance', value: 'ADVANCE'},
            {name: 'Arrears', value: 'ARREARS'}
        ]
    },
    expressionProperties: {
        'templateOptions.options': function($viewValue, $modelValue, scope) {
                if(scope.model.advanceOrArrears) {
                    $scope.to.options.splice(0, 0, {name: '', value: ''});
                }
        }
    }
}

HTML

<form name="vm.form" ng-submit="vm.saveForm()" novalidate>
        <formly-form model="vm.model" fields="vm.fields"
                     options="vm.options" form="vm.form"></formly-form>
        <button class="btn top20 btn-primary" type="submit">Save</button>
</form>

This 'sort of' work as it adds an empty option that doesn't disappear but I end up with 2 empty options to start with before I select one of the options...

options: [
    {name: '', value: ''},
    {name: 'Advance', value: 'ADVANCE'},
    {name: 'Arrears', value: 'ARREARS'}
]
LazioTibijczyk
  • 1,701
  • 21
  • 48

0 Answers0