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. 18
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  3. 4
      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>
<div *ngSwitchCase="'Dropdown'"> <div *ngSwitchCase="'Dropdown'">
<select class="form-control" [formControlName]="partition"> <select class="form-control" [formControlName]="partition">
<option></option> <option [ngValue]="null"></option>
<option *ngFor="let value of field.properties.allowedValues" [ngValue]="value">{{value}}</option> <option *ngFor="let value of field.properties.allowedValues" [ngValue]="value">{{value}}</option>
</select> </select>
</div> </div>
@ -60,6 +60,7 @@
</div> </div>
<div *ngSwitchCase="'Dropdown'"> <div *ngSwitchCase="'Dropdown'">
<select class="form-control" [formControlName]="partition"> <select class="form-control" [formControlName]="partition">
<option [ngValue]="null"></option>
<option *ngFor="let value of field.properties.allowedValues" [ngValue]="value">{{value}}</option> <option *ngFor="let value of field.properties.allowedValues" [ngValue]="value">{{value}}</option>
</select> </select>
</div> </div>

18
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']); fieldForm.controls['iv'].setValue(fieldValue['iv'] === undefined ? null : fieldValue['iv']);
} }
} }
if (this.content.status === 'Archived') { if (this.content.status === 'Archived') {
this.contentForm.disable(); 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);
}
}
}
}
} }
} }
} }

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

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

Loading…
Cancel
Save