如何验证并滚动到 sap.m.RadioButtonGroup
How to validate and scroll to sap.m.RadioButtonGroup
任务很简单:
用户必须 select 一组单选按钮中的一个条目,否则验证将失败。
为了对用户友好,我还想在验证失败时滚动到 RadioButtonGroup,因为它在更下方并且可能不可见(如我在下面链接的示例中所示)。
实施对我来说不是那么直接,因为 RadioButtonGroup 没有 属性 required
.
Here's my code example - RadioButtonGroup 在文件 SomeView.view.xml
的第 420 行...
到目前为止我还没有真正尝试过任何东西,因为我不知道该尝试什么。
有谁知道在不影响现有验证器实现(我从 here 获得)的情况下这是否可行?
The implementation is not so straight forward to me because RadioButtonGroup does not have the property required.
只有 sap.m.Label
需要 属性 required="true"
。不是控件 sap.m.RadioButtonGroup
本身。
控件 sap.m.RadioButtonGroup
有一个名为 selectedIndex
的 属性。在您的 Code-Snippet 中,您设置了 属性 selectedIndex="-1"
。如果用户选择 sap.m.Radiobutton
,则 selectedIndex
将更改为 0..3。让我们用 sap.ui.model.type.Integer
.
捕捉它
// JSON dummy data
var oData = {
text : "Test",
userEmail : "i.am@groot.com",
number : 50,
date : "01.01.2021",
selectedIndex: -1
};
<Label text="Final answer?" required="true"/>
<RadioButtonGroup
id="answer"
columns="4"
selectedIndex="{ path: '/selectedIndex',
type: 'sap.ui.model.type.Integer',
constraints : {
minimum : 0,
maximum : 3
}}">
<RadioButton id="A1" text="A"/>
<RadioButton id="B1" text="B"/>
<RadioButton id="C1" text="C"/>
<RadioButton id="D1" text="D"/>
</RadioButtonGroup>
Validator.js
仅检查以下属性
aValidateProperties = ["value", "selectedKey", "text"]
所以我们添加属性 selectedIndex
aValidateProperties = ["value", "selectedKey", "text", "selectedIndex"]
现在可以验证了! Code-Example
In order to be nice to the user, I'd also like to scroll to that RadioButtonGroup when its validation fails since it's further down and may not be in sight (as in my example linked below).
任务很简单:
用户必须 select 一组单选按钮中的一个条目,否则验证将失败。
为了对用户友好,我还想在验证失败时滚动到 RadioButtonGroup,因为它在更下方并且可能不可见(如我在下面链接的示例中所示)。
实施对我来说不是那么直接,因为 RadioButtonGroup 没有 属性 required
.
Here's my code example - RadioButtonGroup 在文件 SomeView.view.xml
的第 420 行...
到目前为止我还没有真正尝试过任何东西,因为我不知道该尝试什么。
有谁知道在不影响现有验证器实现(我从 here 获得)的情况下这是否可行?
The implementation is not so straight forward to me because RadioButtonGroup does not have the property required.
只有 sap.m.Label
需要 属性 required="true"
。不是控件 sap.m.RadioButtonGroup
本身。
控件 sap.m.RadioButtonGroup
有一个名为 selectedIndex
的 属性。在您的 Code-Snippet 中,您设置了 属性 selectedIndex="-1"
。如果用户选择 sap.m.Radiobutton
,则 selectedIndex
将更改为 0..3。让我们用 sap.ui.model.type.Integer
.
// JSON dummy data
var oData = {
text : "Test",
userEmail : "i.am@groot.com",
number : 50,
date : "01.01.2021",
selectedIndex: -1
};
<Label text="Final answer?" required="true"/>
<RadioButtonGroup
id="answer"
columns="4"
selectedIndex="{ path: '/selectedIndex',
type: 'sap.ui.model.type.Integer',
constraints : {
minimum : 0,
maximum : 3
}}">
<RadioButton id="A1" text="A"/>
<RadioButton id="B1" text="B"/>
<RadioButton id="C1" text="C"/>
<RadioButton id="D1" text="D"/>
</RadioButtonGroup>
Validator.js
仅检查以下属性
aValidateProperties = ["value", "selectedKey", "text"]
所以我们添加属性 selectedIndex
aValidateProperties = ["value", "selectedKey", "text", "selectedIndex"]
现在可以验证了! Code-Example
In order to be nice to the user, I'd also like to scroll to that RadioButtonGroup when its validation fails since it's further down and may not be in sight (as in my example linked below).