formly-js / angular-formly

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

Retrieving properties from different fields in single template. #688

Closed Jan539 closed 8 years ago

Jan539 commented 8 years ago

Hey,

Problem I am trying to create a label template that looks like this:

label1, label2:     [textInput1] [textInput2]

Where label1 belongs to field textInput1 and label2 to textInput2.

I found a solution but I don't like it. I'm using a wrapper to wrap my labels around a fieldGroup of two input fields:

twoLabels.html

<div>
  <div>
    <label for="{{to.id1}}" ng-if="to.label1">{{to.label1}}</label>
  </div>
  <div class="inline-form-set__label">
    <label for="{{to.id2}}" ng-if="to.label2">{{to.label2}}</label>
  </div>
</div>
<formly-transclude></formly-transclude>

myFields

public userFields = [
{
  fieldGroup: [
    {
      id: 'myFirstName',
      type: 'myInput',
      key: 'firstName'
    },
    {
      id: 'myLastName',
      type: 'myInput',
      key: 'lastName'
    }
  ],
  wrapper: [ "twoLabel" ],
  templateOptions: {
    label1: "test1",
    label2: "test2",
    id1: "myFirstName",
    id2: "myLastName"
  }
}
]

The reason why I dislike it is because I have to set the ids manually and the labels are detached from the fields. Also in the documention it's stated that one should avoid this.

Request I would like to have the possibility to retrieve the ids of different fields in label.html, e.g. via fg[0].id and fg[1].id or smth like this.

Jan539 commented 8 years ago

Ok nvm i figured I can use options.fieldGroup[0].id for this.