Feat polifill for getFirstError and make existsError accept more than one field (kcContext.messagePerField)
This commit is contained in:
parent
00651c0c3c
commit
a0367066b4
@ -79,47 +79,61 @@
|
|||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
},
|
},
|
||||||
"existsError": function (fieldName) {
|
"existsError": function (){
|
||||||
|
|
||||||
<#if !messagesPerField?? || !(messagesPerField?is_hash)>
|
function existsError_singleFieldName(fieldName) {
|
||||||
throw new Error("You're not supposed to use messagesPerField.printIfExists in this page");
|
|
||||||
<#else>
|
|
||||||
<#list fieldNames as fieldName>
|
|
||||||
if(fieldName === "${fieldName}" ){
|
|
||||||
|
|
||||||
<#-- https://github.com/keycloakify/keycloakify/pull/218 -->
|
<#if !messagesPerField?? || !(messagesPerField?is_hash)>
|
||||||
<#if ('${fieldName}' == 'username' || '${fieldName}' == 'password') && pageId != 'register.ftl' && pageId != 'register-user-profile.ftl'>
|
throw new Error("You're not supposed to use messagesPerField.printIfExists in this page");
|
||||||
|
<#else>
|
||||||
|
<#list fieldNames as fieldName>
|
||||||
|
if(fieldName === "${fieldName}" ){
|
||||||
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = "">
|
<#-- https://github.com/keycloakify/keycloakify/pull/218 -->
|
||||||
|
<#if ('${fieldName}' == 'username' || '${fieldName}' == 'password') && pageId != 'register.ftl' && pageId != 'register-user-profile.ftl'>
|
||||||
|
|
||||||
<#attempt>
|
<#assign doExistErrorOnUsernameOrPassword = "">
|
||||||
<#assign doExistErrorOnUsernameOrPassword = messagesPerField.existsError('username', 'password')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = true>
|
|
||||||
</#attempt>
|
|
||||||
|
|
||||||
return <#if doExistErrorOnUsernameOrPassword>true<#else>false</#if>;
|
<#attempt>
|
||||||
|
<#assign doExistErrorOnUsernameOrPassword = messagesPerField.existsError('username', 'password')>
|
||||||
|
<#recover>
|
||||||
|
<#assign doExistErrorOnUsernameOrPassword = true>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
<#else>
|
return <#if doExistErrorOnUsernameOrPassword>true<#else>false</#if>;
|
||||||
|
|
||||||
<#assign doExistErrorMessageForField = "">
|
<#else>
|
||||||
|
|
||||||
<#attempt>
|
<#assign doExistErrorMessageForField = "">
|
||||||
<#assign doExistErrorMessageForField = messagesPerField.existsError('${fieldName}')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistErrorMessageForField = true>
|
|
||||||
</#attempt>
|
|
||||||
|
|
||||||
return <#if doExistErrorMessageForField>true<#else>false</#if>;
|
<#attempt>
|
||||||
|
<#assign doExistErrorMessageForField = messagesPerField.existsError('${fieldName}')>
|
||||||
|
<#recover>
|
||||||
|
<#assign doExistErrorMessageForField = true>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
</#if>
|
return <#if doExistErrorMessageForField>true<#else>false</#if>;
|
||||||
|
|
||||||
}
|
</#if>
|
||||||
</#list>
|
|
||||||
|
|
||||||
throw new Error(fieldName + "is probably runtime generated, see: https://docs.keycloakify.dev/limitations#field-names-cant-be-runtime-generated");
|
}
|
||||||
|
</#list>
|
||||||
|
|
||||||
</#if>
|
throw new Error(fieldName + "is probably runtime generated, see: https://docs.keycloakify.dev/limitations#field-names-cant-be-runtime-generated");
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for( let i = 0; i < arguments.length; i++ ){
|
||||||
|
|
||||||
|
if( existsError_singleFieldName(arguments[i]) ){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
},
|
},
|
||||||
"get": function (fieldName) {
|
"get": function (fieldName) {
|
||||||
@ -219,6 +233,19 @@
|
|||||||
throw new Error(fieldName + "is probably runtime generated, see: https://docs.keycloakify.dev/limitations#field-names-cant-be-runtime-generated");
|
throw new Error(fieldName + "is probably runtime generated, see: https://docs.keycloakify.dev/limitations#field-names-cant-be-runtime-generated");
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
|
},
|
||||||
|
"getFirstError": function () {
|
||||||
|
|
||||||
|
for( let i = 0; i < arguments.length; i++ ){
|
||||||
|
|
||||||
|
const fieldName = arguments[i];
|
||||||
|
|
||||||
|
if( out.messagesPerField.existsError(fieldName) ){
|
||||||
|
return out.messagesPerField.get(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ export declare namespace KcContext {
|
|||||||
* @param fields
|
* @param fields
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
existsError: (fieldName: string) => boolean;
|
existsError: (fieldName: string, ...otherFiledNames: string[]) => boolean;
|
||||||
/**
|
/**
|
||||||
* Get message for given field.
|
* Get message for given field.
|
||||||
*
|
*
|
||||||
@ -116,6 +116,8 @@ export declare namespace KcContext {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
exists: (fieldName: string) => boolean;
|
exists: (fieldName: string) => boolean;
|
||||||
|
|
||||||
|
getFirstError: (...fieldNames: string[]) => string;
|
||||||
};
|
};
|
||||||
properties: Record<string, string | undefined>;
|
properties: Record<string, string | undefined>;
|
||||||
authenticationSession?: {
|
authenticationSession?: {
|
||||||
@ -165,6 +167,7 @@ export declare namespace KcContext {
|
|||||||
alias: string;
|
alias: string;
|
||||||
providerId: string;
|
providerId: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
|
iconClasses?: string;
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user