Hello,
I am trying to implement a case where the user needs to see the % sign when he starts to enter in a field which contains an percentage amount.
The actual field contains a decimal where 1.0 is 100% (which is a common percentage value storage approach).
My edit mask is set to '999.99%'.
This is some sample code:
private class MyType extends SimpleType {
public MyType() {
super("mine", FieldType.ANY);
}
}
@Override
public Canvas getViewPanel() {
new MyType().register();
DynamicForm form = new DynamicForm();
form.setWidth(400);
TextItem percentageField = new TextItem("percentageItem", "Percentage");
percentageField.setAttribute("type", "mine");
percentageField.setMask("999.99%");
percentageField.setValue(0.1234);
percentageField.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
SC.say(event.getValue().toString());
}
});
form.setFields(percentageField);
return form;
}
Several things are going wrong:
- the value is not correctly formatted
- when I enter a new value the decimal is completely ignored
As far as I can tell this is probably caused by the fact that the edit mask is not supposed to be used for numerical fields, is that assumption correct?
How could I implement this kind of scenario, I would find it odd that we are the 1st to try an edit mask on a percentage field?
Many thanks for your insights!
I am trying to implement a case where the user needs to see the % sign when he starts to enter in a field which contains an percentage amount.
The actual field contains a decimal where 1.0 is 100% (which is a common percentage value storage approach).
My edit mask is set to '999.99%'.
This is some sample code:
private class MyType extends SimpleType {
public MyType() {
super("mine", FieldType.ANY);
}
}
@Override
public Canvas getViewPanel() {
new MyType().register();
DynamicForm form = new DynamicForm();
form.setWidth(400);
TextItem percentageField = new TextItem("percentageItem", "Percentage");
percentageField.setAttribute("type", "mine");
percentageField.setMask("999.99%");
percentageField.setValue(0.1234);
percentageField.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
SC.say(event.getValue().toString());
}
});
form.setFields(percentageField);
return form;
}
Several things are going wrong:
- the value is not correctly formatted
- when I enter a new value the decimal is completely ignored
As far as I can tell this is probably caused by the fact that the edit mask is not supposed to be used for numerical fields, is that assumption correct?
How could I implement this kind of scenario, I would find it odd that we are the 1st to try an edit mask on a percentage field?
Many thanks for your insights!
Comment