From ab906ec4178ec2ba7faf7e3eea1e094dc9f77cc3 Mon Sep 17 00:00:00 2001 From: garronej Date: Sat, 15 Oct 2022 14:22:11 +0200 Subject: [PATCH] #192: fix bad logic in ftl to js script --- ..._object_to_js_code_declaring_an_object.ftl | 80 ++++++++++--------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl b/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl index 050e7637..07167ff4 100644 --- a/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +++ b/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl @@ -32,60 +32,64 @@ ${ftl_object_to_js_code_declaring_an_object(.data_model, [])?no_esc}; "printIfExists": function (fieldName, x) { <#if !messagesPerField?? > return undefined; + <#else> + <#list fieldNames as fieldName> + if(fieldName === "${fieldName}" ){ + <#attempt> + return "${messagesPerField.printIfExists(fieldName,'1')}" ? x : undefined; + <#recover> + + } + + throw new Error("There is no " + fieldName + " field"); - <#list fieldNames as fieldName> - if(fieldName === "${fieldName}" ){ - <#attempt> - return "${messagesPerField.printIfExists(fieldName,'1')}" ? x : undefined; - <#recover> - - } - - throw new Error("There is no " + fieldName + " field"); }, "existsError": function (fieldName) { <#if !messagesPerField?? > return false; + <#else> + <#list fieldNames as fieldName> + if(fieldName === "${fieldName}" ){ + <#attempt> + return <#if messagesPerField.existsError('${fieldName}')>true<#else>false; + <#recover> + + } + + throw new Error("There is no " + fieldName + " field"); - <#list fieldNames as fieldName> - if(fieldName === "${fieldName}" ){ - <#attempt> - return <#if messagesPerField.existsError('${fieldName}')>true<#else>false; - <#recover> - - } - - throw new Error("There is no " + fieldName + " field"); }, "get": function (fieldName) { <#if !messagesPerField?? > return ''; + <#else> + <#list fieldNames as fieldName> + if(fieldName === "${fieldName}" ){ + <#attempt> + <#if messagesPerField.existsError('${fieldName}')> + return "${messagesPerField.get('${fieldName}')?no_esc}"; + + <#recover> + + } + + throw new Error("There is no " + fieldName + " field"); - <#list fieldNames as fieldName> - if(fieldName === "${fieldName}" ){ - <#attempt> - <#if messagesPerField.existsError('${fieldName}')> - return "${messagesPerField.get('${fieldName}')?no_esc}"; - - <#recover> - - } - - throw new Error("There is no " + fieldName + " field"); }, "exists": function (fieldName) { <#if !messagesPerField?? > return false; + <#else> + <#list fieldNames as fieldName> + if(fieldName === "${fieldName}" ){ + <#attempt> + return <#if messagesPerField.exists('${fieldName}')>true<#else>false; + <#recover> + + } + + throw new Error("There is no " + fieldName + " field"); - <#list fieldNames as fieldName> - if(fieldName === "${fieldName}" ){ - <#attempt> - return <#if messagesPerField.exists('${fieldName}')>true<#else>false; - <#recover> - - } - - throw new Error("There is no " + fieldName + " field"); } };