-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(application-system): Add clear on change (#17452)
* Add shared clearing handler * Add clearOnChange support to fieldbuilders and types * Add clearOnChange support to controllers * Add clearOnChange support to formfields * Cleanup * Add demonstration to example application * Add extra info
- Loading branch information
1 parent
1a3606f
commit 1364f19
Showing
27 changed files
with
260 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
.../reference-template/src/forms/exampleForm/commonActionsSection/clearOnChangeSubsection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { | ||
buildAsyncSelectField, | ||
buildCheckboxField, | ||
buildDateField, | ||
buildDescriptionField, | ||
buildDividerField, | ||
buildMultiField, | ||
buildNationalIdWithNameField, | ||
buildPhoneField, | ||
buildRadioField, | ||
buildSelectField, | ||
buildSubSection, | ||
buildTextField, | ||
} from '@island.is/application/core' | ||
import { FriggSchoolsByMunicipality } from '../../../utils/types' | ||
import { friggSchoolsByMunicipalityQuery } from '../../../graphql/sampleQuery' | ||
|
||
export const clearOnChangeSubsection = buildSubSection({ | ||
id: 'clearOnChangeSubsection', | ||
title: 'Clear on change', | ||
children: [ | ||
buildMultiField({ | ||
id: 'clearOnChangeMultiField', | ||
title: 'Clear on change', | ||
children: [ | ||
buildDescriptionField({ | ||
id: 'descriptionField', | ||
title: '', | ||
description: `Clear on change allows a field to clear other fields when its value or selection changes. | ||
Below are some examples of fields that will clear the bottom field when changed. | ||
Note that the fields that are cleared can be anywhere in the application, not just on the same screen.`, | ||
}), | ||
buildDescriptionField({ | ||
id: 'descriptionField2', | ||
title: '', | ||
description: `To try it out simply enter some text in the bottom text field | ||
and change the selections in any of the other fields.`, | ||
}), | ||
buildAsyncSelectField({ | ||
id: 'asyncSelectField', | ||
title: 'Async Select', | ||
loadingError: 'Loading error', | ||
clearOnChange: ['clearableTextField'], | ||
loadOptions: async ({ apolloClient }) => { | ||
const { data } = | ||
await apolloClient.query<FriggSchoolsByMunicipality>({ | ||
query: friggSchoolsByMunicipalityQuery, | ||
}) | ||
|
||
return ( | ||
data?.friggSchoolsByMunicipality?.map((municipality) => ({ | ||
value: municipality.name, | ||
label: municipality.name, | ||
})) ?? [] | ||
) | ||
}, | ||
}), | ||
|
||
buildSelectField({ | ||
id: 'selectField', | ||
title: 'Select', | ||
clearOnChange: ['clearableTextField'], | ||
options: [ | ||
{ value: 'option1', label: 'Option 1' }, | ||
{ value: 'option2', label: 'Option 2' }, | ||
], | ||
}), | ||
|
||
buildPhoneField({ | ||
id: 'phoneField', | ||
title: 'Phone Field', | ||
clearOnChange: ['clearableTextField'], | ||
}), | ||
|
||
buildDateField({ | ||
id: 'dateField', | ||
title: 'Date Field', | ||
clearOnChange: ['clearableTextField'], | ||
}), | ||
|
||
buildTextField({ | ||
id: 'textField', | ||
title: 'Text Field', | ||
clearOnChange: ['clearableTextField'], | ||
}), | ||
|
||
buildRadioField({ | ||
id: 'radioField', | ||
title: 'Radio Field', | ||
clearOnChange: ['clearableTextField'], | ||
options: [ | ||
{ value: 'option1', label: 'Option 1' }, | ||
{ value: 'option2', label: 'Option 2' }, | ||
], | ||
}), | ||
|
||
buildCheckboxField({ | ||
id: 'checkboxField', | ||
title: 'Checkbox Field', | ||
marginTop: 2, | ||
clearOnChange: ['clearableTextField'], | ||
options: [ | ||
{ value: 'option1', label: 'Option 1' }, | ||
{ value: 'option2', label: 'Option 2' }, | ||
], | ||
}), | ||
|
||
buildNationalIdWithNameField({ | ||
id: 'nationalIdWithNameField', | ||
title: 'NationalId With Name Field', | ||
clearOnChange: ['clearableTextField'], | ||
}), | ||
|
||
buildDividerField({}), | ||
|
||
buildTextField({ | ||
id: 'clearableTextField', | ||
title: 'Clearable TextField', | ||
placeholder: 'Text entered here will be cleared', | ||
}), | ||
], | ||
}), | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.