UI Builder Script or Event
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 07:23 AM
Hi guys!
I'm having a problem with UI Builder. I have a fillable field, where it has an event that when the user “blurs” the field, it corrects possible spaces and lowercase letters to uppercase letters. The event pulls up a Client Script that does this validation. It's working, but when I test it the first time, it corrects it just fine, but when I test it a second time, nothing happens, as if it didn't pull the script.
Can you help me?
Script:
/**
* @Param {params} params
* @Param {api} params.api
* @Param {any} params.event
* @Param {any} params.imports
* @Param {ApiHelpers} params.helpers
*/
function handler({
api,
event,
helpers,
imports
}) {
try {
var numeroProtocolo = api.state.protocoloSelecionado;
// Remove espaços extras e transforma em maiúsculo
var codigo = numeroProtocolo ? numeroProtocolo.trim().toUpperCase() : "";
// Validação do padrão correto
var codigoInvalido = !codigo.startsWith("CE") ||
!codigo.endsWith("C") ||
codigo.length !== 11;
if (codigoInvalido) {
// Apaga tudo se não for exatamente o que esperamos
api.setState('protocoloSelecionado', "");
api.setState('hideEnviar', true);
} else {
// Valor válido — mantemos ele corrigido
api.setState('protocoloSelecionado', codigo);
api.setState('hideEnviar', false);
}
console.log("console: " + codigo);
}
catch (e) {
console.log(e);
}
}
Event on attach.
0 REPLIES 0