Browse Source

Display Default Values in UI

pull/198/head
Derek Begnoche 8 years ago
parent
commit
47b467c786
  1. 3
      src/Squidex/app/features/content/pages/content/content-field.component.html
  2. 20
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  3. 6
      src/Squidex/app/shared/services/schemas.service.ts

3
src/Squidex/app/features/content/pages/content/content-field.component.html

@ -31,7 +31,7 @@
</div>
<div *ngSwitchCase="'Dropdown'">
<select class="form-control" [formControlName]="partition">
<option></option>
<option [ngValue]="null"></option>
<option *ngFor="let value of field.properties.allowedValues" [ngValue]="value">{{value}}</option>
</select>
</div>
@ -60,6 +60,7 @@
</div>
<div *ngSwitchCase="'Dropdown'">
<select class="form-control" [formControlName]="partition">
<option [ngValue]="null"></option>
<option *ngFor="let value of field.properties.allowedValues" [ngValue]="value">{{value}}</option>
</select>
</div>

20
src/Squidex/app/features/content/pages/content/content-page.component.ts

@ -256,11 +256,25 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy,
fieldForm.controls['iv'].setValue(fieldValue['iv'] === undefined ? null : fieldValue['iv']);
}
}
if (this.content.status === 'Archived') {
this.contentForm.disable();
}
} else {
for (const field of this.schema.fields) {
if (field.properties.hasOwnProperty('defaultValue')) {
const defaultValue = (field.properties as any).defaultValue;
if (defaultValue) {
const fieldForm = <FormGroup>this.contentForm.get(field.name);
if (field.partitioning === 'language') {
for (let language of this.languages) {
fieldForm.controls[language.iso2Code].setValue(defaultValue);
}
} else {
fieldForm.controls['iv'].setValue(defaultValue);
}
}
}
}
}
}
}
}

6
src/Squidex/app/shared/services/schemas.service.ts

@ -426,7 +426,11 @@ export class NumberFieldPropertiesDto extends FieldPropertiesDto {
}
if (this.allowedValues && this.allowedValues.length > 0) {
validators.push(ValidatorsEx.validValues(this.allowedValues));
if (this.isRequired && !isOptional) {
validators.push(ValidatorsEx.validValues(this.allowedValues));
} else {
validators.push(ValidatorsEx.validValues(this.allowedValues.concat([null])));
}
}
return validators;

Loading…
Cancel
Save