I mean https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/event/InputEvent.html#getValue--
hawk ( 2022-03-04 18:16:34 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi Guys I have a textbox that reached 255 characters must show a tooltiptext with the words: "Character limit reached" and at the same time the textbox must be colored red, not inside but in the edges, now this is my zul file, the tooltip also appears when the textbox is empty, how can I do from zul to set my logic that is: when the textbox reaches 255 characters the tooltip text must appear and the border of the textbox must be colored red. Thank you. Modal.zul
<div>
<textbox id="textbox" width="500px" tooltiptext="${labels.label.tooltiptext}" />
</div>
controller.java
@SocketEvent(socketId = "inputObject")
public void onInputObject(final OccupationModel model)
{
if(Objects.nonNull(model))
{
setCurrentModel(model);
}
textbox.setMultiline(true);
textbox.setMaxlength(255);
}
@hawk this is ok? image below :
@hawk zul file:
The error message keeps showing until the validation passes. This approach also fails the validation.
<zscript><![CDATA[
CharacterLimitConstraint charLimitConstraint = new CharacterLimitConstraint(10);
]]></zscript>
10 characters limit: <textbox instant="true" constraint="${charLimitConstraint}"/>
instant="true"
, it will validate whilepublic class CharacterLimitConstraint implements Constraint {
private int maxLength;
public CharacterLimitConstraint(int maxLength) {
this.maxLength = maxLength;
}
public void validate(Component comp, Object value) throws WrongValueException {
if (value != null && value.toString().length() >= maxLength)
throw new WrongValueException(comp, maxLength + " character limit reached ");
}
}
It just shows the info, doesn't produce validation failure. The popup closes when a user clicks outside the popup.
InputEvent.getValue()
Popup.open()
to show the error message.
call Textbox.addSclass()
to apply a predefined CSS class to decorate red edge of the textbox. Textbox.removeSclass()
I mean https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/event/InputEvent.html#getValue--
hawk ( 2022-03-04 18:16:34 +0800 )editit looks like your system wraps zk API. I don't see any InputEvent
pass into exceedLimit()
. @ViewEvent
is not a ZK annotation.
If you listen onChanging
event with SelectorComposer
(ref: Listener_Autowiring), ZK will pass InputEvent into the listener method like:
public class MyComposer extends SelectorComposer<Component>{
@Listen("onChanging = #mytextbox")
public void onCellClick(InputEvent e) {
}
}
If your system wraps zk event listening API, you need to find your way to get InputEvent
.
sorry, forget that a tooltip doesn't show actively without a mouse hovering. You should use Popup.open() to show a popup, please see https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zul/Popup.html
hawk ( 2022-03-04 22:55:26 +0800 )editTo set red border:
<style>
.red-border{
border: solid 1px red;
}
</style>
<textbox sclass="red-border"/>
Asked: 2022-03-03 20:15:01 +0800
Seen: 17 times
Last updated: Mar 09 '22