From 9998a514f3f28077a2eb3bea2bd2885b4d2a0883 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 17 May 2021 16:31:23 -0400 Subject: [PATCH] get groupName from model --- MVMCoreUI/FormUIHelpers/FormValidator.swift | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index 28029397..f27bb968 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -114,8 +114,8 @@ import MVMCore // TODO: Temporary hacks, rewrite architecture to support this. public extension FormValidator { - func addFormParams(requestParameters: MVMCoreRequestParameters, model: (MoleculeModelProtocol & FormFieldProtocol)?) { - let groupName = model?.groupName ?? FormValidator.defaultGroupName + func addFormParams(requestParameters: MVMCoreRequestParameters, model: (MoleculeModelProtocol & FormItemProtocol)?) { + let groupName = model?.groupName ?? getGroupName(forPageType: requestParameters.pageType) ?? FormValidator.defaultGroupName let formParams = getFormParams(forGroup: groupName) requestParameters.add(formParams) } @@ -132,3 +132,20 @@ public extension FormValidator { return extraParam } } + +// TODO: Temporary hacks, rewrite architecture to support this. +public extension FormValidator { + + func getGroupName(forPageType pageType: String?) -> String? { + + for actionItem in groupWatchers { + if let buttonModel = actionItem as? ButtonModel, + pageType == (buttonModel.action as? ActionOpenPageProtocol)?.pageType { + return buttonModel.groupName + } + } + + return nil + } +} +