Browse Source

Fix `The additionally added mandatory propertie is functionally different from other mandatory fields and localization seems broken`

pull/13700/head
Mahmut Gundogdu 4 years ago
parent
commit
98cfe7cb26
  1. 3
      npm/ng-packs/packages/core/src/lib/validators/required.validator.ts
  2. 2
      npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.html
  3. 8
      npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts

3
npm/ng-packs/packages/core/src/lib/validators/required.validator.ts

@ -9,9 +9,10 @@ export interface RequiredOptions {
} }
export function validateRequired({ allowEmptyStrings }: RequiredOptions = {}): ValidatorFn { export function validateRequired({ allowEmptyStrings }: RequiredOptions = {}): ValidatorFn {
return (control: AbstractControl): RequiredError | null => { const required = (control: AbstractControl): RequiredError | null => {
return isValidRequired(control.value, allowEmptyStrings) ? null : { required: true }; return isValidRequired(control.value, allowEmptyStrings) ? null : { required: true };
}; };
return required;
} }
function isValidRequired(value: any, allowEmptyStrings: boolean): boolean { function isValidRequired(value: any, allowEmptyStrings: boolean): boolean {

2
npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.html

@ -146,7 +146,7 @@
</ng-container> </ng-container>
<ng-template #label let-classes> <ng-template #label let-classes>
<label [htmlFor]="prop.id" [ngClass]="classes || 'form-label'" <label [htmlFor]="prop.id" [ngClass]="classes || 'form-label'" x
>{{ prop.displayName | abpLocalization }} {{ asterisk }}</label >{{ prop.displayName | abpLocalization }} {{ asterisk }}</label
> >
</ng-template> </ng-template>

8
npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts

@ -1,4 +1,4 @@
import { EXTENSIONS_FORM_PROP_DATA, EXTENSIONS_FORM_PROP } from './../../tokens/extensions.token'; import {EXTENSIONS_FORM_PROP_DATA, EXTENSIONS_FORM_PROP} from './../../tokens/extensions.token';
import {ABP, AbpValidators, ConfigStateService, TrackByService} from '@abp/ng.core'; import {ABP, AbpValidators, ConfigStateService, TrackByService} from '@abp/ng.core';
import { import {
AfterViewInit, AfterViewInit,
@ -181,7 +181,7 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
} }
} }
ngOnChanges({prop,data}: SimpleChanges) { ngOnChanges({prop, data}: SimpleChanges) {
const currentProp = prop?.currentValue as FormProp; const currentProp = prop?.currentValue as FormProp;
const {options, readonly, disabled, validators, template} = currentProp || {}; const {options, readonly, disabled, validators, template} = currentProp || {};
if (template) { if (template) {
@ -195,7 +195,7 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
provide: EXTENSIONS_FORM_PROP_DATA, provide: EXTENSIONS_FORM_PROP_DATA,
useValue: (data?.currentValue as PropData)?.record useValue: (data?.currentValue as PropData)?.record
}, },
{ provide: ControlContainer, useExisting: FormGroupDirective } {provide: ControlContainer, useExisting: FormGroupDirective}
], ],
parent: this.injector, parent: this.injector,
}); });
@ -219,5 +219,5 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
} }
function isRequired(validator: ValidatorFn) { function isRequired(validator: ValidatorFn) {
return validator === Validators.required || validator === AbpValidators.required; return validator === Validators.required || validator === AbpValidators.required || validator.name === 'required';
} }

Loading…
Cancel
Save