Skip to main contentMAF Configuration Practices

Clear datasource warnings

About this task

Datasources plays a essential role in the apps, as well as components that are tightly coupled to datasources. In this example, we will focus on the relation with smart-input component. This component has a strong link with datasource because it relies on schema information to prepare its input type and validates data entered as value. Now, validations considers properties enabled in the component and with information received in the datasource. For instance, ‘required’ prop not only demands for any value entered in the field but also for warnings and errors emitted from the datasource associated to it. In this configuration, we create some logs to identify warnings preventing required property of a smart-input to be fullfilled and also provide a way to clear those warnings once confirmed they are harmless.

Procedure

Step 1: Create a handler for field-warning event and add condition to match the field we are looking for.

'field-warning' = ({item, field, warning}) => {
if (warning) {
console.log(`**CUSTOM*** Tracking field warning on field ${field}`);
if (field === "location" ) {
console.log('**CUSTOM*** Ensure we observing warning to location field')
console.log({field, item, warning});
}
}
}

Step 2: Once identified the type and the meaning of the warning we can clear the warnings coming from there.

onValueChanged({change, datasource, field, item, newValue, oldValue}) {
if (datasource.name === "dsCreateWo"){
console.log(`**CUSTOM*** Tracking changes for dsCreateWo on field ${field} for value ${newValue}`);
if (field === "location" ) {
console.log('**CUSTOM*** Ensure we observing and cleaning location warning')
console.log({change, datasource, field, item, newValue});
datasource.clearWarnings(item, field);
}
}