Skip to content

Commit 8d03034

Browse files
committed
refactoring
1 parent 7cd2482 commit 8d03034

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ export class DynamicForm extends React.Component<
207207
val.fieldDefaultValue = null;
208208
shouldBeReturnBack = true;
209209
}
210-
} else if(val.fieldType === "Number"){
211-
if(!val.showAsPercentage){
212-
if((val.newValue < val.minimumValue) || (val.newValue > val.maximumValue)){
210+
} else if (val.fieldType === "Number") {
211+
if (!val.showAsPercentage) {
212+
if ((val.newValue < val.minimumValue) || (val.newValue > val.maximumValue)) {
213213
shouldBeReturnBack = true;
214214
}
215215
}
@@ -364,9 +364,9 @@ export class DynamicForm extends React.Component<
364364
const folderTitle =
365365
objects[titleField] !== undefined && objects[titleField] !== ""
366366
? (objects[titleField] as string).replace(
367-
/["|*|:|<|>|?|/|\\||]/g,
368-
"_"
369-
) // Replace not allowed chars in folder name
367+
/["|*|:|<|>|?|/|\\||]/g,
368+
"_"
369+
) // Replace not allowed chars in folder name
370370
: ""; // Empty string will be replaced by SPO with Folder Item ID
371371
const newFolder = await library.rootFolder.addSubFolderUsingPath(
372372
folderTitle
@@ -715,9 +715,9 @@ export class DynamicForm extends React.Component<
715715
listItemId: listItemId,
716716
principalType: principalType,
717717
description: field.Description,
718-
maximumValue:field.MaximumValue,
719-
minimumValue:field.MinimumValue,
720-
showAsPercentage:field.ShowAsPercentage
718+
maximumValue: field.MaximumValue,
719+
minimumValue: field.MinimumValue,
720+
showAsPercentage: field.ShowAsPercentage
721721
});
722722
tempFields.sort((a, b) => a.Order - b.Order);
723723
}

src/controls/dynamicForm/dynamicField/DynamicField.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
9595

9696
const labelEl = <label className={(required) ? styles.fieldRequired + ' ' + styles.fieldLabel : styles.fieldLabel}>{labelText}</label>;
9797
const errorText = this.getRequiredErrorText();
98-
const errorTextforNumber = this.getnumberErrorText();
98+
const errorTextforNumber = this.getNumberErrorText();
9999
const errorTextEl = <text className={styles.errormessage}>{errorText}</text>;
100100
const descriptionEl = <text className={styles.fieldDescription}>{description}</text>;
101101
const hasImage = !!changedValue;
@@ -139,7 +139,7 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
139139
value={value}
140140
className={styles.fieldDisplay}
141141
onChange={(newText) => { this.onChange(newText); return newText; }}
142-
isEditMode={!disabled}/>
142+
isEditMode={!disabled} />
143143
{descriptionEl}
144144
{errorTextEl}
145145
</div>;
@@ -588,28 +588,30 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
588588
const {
589589
changedValue
590590
} = this.state;
591-
return (changedValue === undefined || changedValue === ''|| changedValue === null || this.isEmptyArray(changedValue)) && this.props.required ? strings.DynamicFormRequiredErrorMessage : null;
591+
return (changedValue === undefined || changedValue === '' || changedValue === null || this.isEmptyArray(changedValue)) && this.props.required ? strings.DynamicFormRequiredErrorMessage : null;
592592
}
593593

594-
private getnumberErrorText = (): string => {
594+
private getNumberErrorText = (): string => {
595595
const {
596596
changedValue
597597
} = this.state;
598-
const{
598+
const {
599599
maximumValue,
600600
minimumValue,
601601
showAsPercentage
602602
} = this.props;
603603

604-
if((changedValue === undefined || changedValue === ''|| changedValue === null || this.isEmptyArray(changedValue)) && this.props.required){
605-
return strings.DynamicFormRequiredErrorMessage;
606-
} else if((changedValue < minimumValue) || (changedValue > maximumValue)){
607-
if(!showAsPercentage){
608-
return strings.DynamicFormNumberErrorMessage
609-
.replace('{0}', minimumValue.toString())
610-
.replace('{1}', maximumValue.toString());
604+
let errorText: string | null = null;
605+
606+
errorText = this.getRequiredErrorText();
607+
if (!errorText && (changedValue < minimumValue) || (changedValue > maximumValue)) {
608+
if (!showAsPercentage) {
609+
errorText = strings.DynamicFormNumberErrorMessage
610+
.replace('{0}', minimumValue.toString())
611+
.replace('{1}', maximumValue.toString());
611612
}
612613
}
614+
return errorText;
613615
}
614616

615617
private isEmptyArray(value): boolean {

0 commit comments

Comments
 (0)