可以正式交换表单输入和标签吗?

时间:2019-07-11 13:26:59

标签: javascript html angularjs angular-formly

我想在输入焦点时定位正式表单的标签,但是因为正式表单首先生成标签,所以我不能使用同级选择器Map

有没有办法交换它们,以便我们得到类似的东西

.form-control + label

1 个答案:

答案 0 :(得分:0)

是的,您可以编写自定义输入控件

import { Component } from '@angular/core';
import { FieldType } from '@ngx-formly/core';

@Component({
 selector: 'formly-field-input',
 template: `
   <div>
  <input class="form-control ng-pristine ng-untouched ng-valid ng-empty ng-valid-maxlength"
         ng-model="model[options.key]" id="vm.form_input_vehicleRegistration_0" 
         name="vm.form_input_vehicleRegistration_0" formly-custom-validation="" 
         maxlength="20" type="text">
  <label for="vm.form_input_vehicleRegistration_0" class="control-label " ng-if="to.label">
    Registration
  </label>
</div>
 `,
})
export class FormlyFieldInput extends FieldType {}

Example