How to enable a button when filling a textfield with VAADIN











up vote
0
down vote

favorite












I work with Vaadin. I have a text field and a button. My button is initially disabled. When my text field is filled with valid data my button must activate. I can not activate my button. Could you help me ? Thank you



public static DynTextField createFromElement(Element elt, DynForm form) {
if (elt.getNodeName().equals("param") && elt.getAttribute("type").equals("TEXT")) {
DynTextField dtf = new DynTextField();
dtf.setForm(form);
if (elt.hasAttribute("texte"))
dtf.setCaption(elt.getAttribute("texte"));
dtf.nom = elt.getAttribute("nom");
if (elt.hasAttribute("FORMAT"))
dtf.setFormat(elt.getAttribute("FORMAT"));
dtf.setDescription(elt.getAttribute("description"));
dtf.setStyleName("param" + (elt.hasAttribute("class") ? elt.getAttribute("class") : ""));
return dtf;
} else
return null;
}

private void setFormat(String attribute) {
binder = new Binder<>();
binder.forField(this).withValidator(new RegexpValidator("Saisie obligatoire !!", attribute)).asRequired("Format Erroné").bind(No.getter(), No.setter());
//new Binder<>().forField(this).withValidator(new RegexpValidator(attribute, "Format Erroné")).asRequired();

}

// convenience empty getter and setter implementation for better readability
public static class No {
public static <SOURCE, TARGET> ValueProvider<SOURCE, TARGET> getter() {
return source -> null;
}

public static <BEAN, FIELDVALUE> Setter<BEAN, FIELDVALUE> setter() {
return (bean, fieldValue) -> {
//no op
};
}
}


The program that creates my button. This is where I would like to make my button active.



public DynButton(DynForm form, String as400PGMName, String parameterList) {
super(VaadinIcons.CHECK);
this.as400PGMName = as400PGMName;
if (parameterList.length == 1 && parameterList[0].equals(""))
this.parameterList = new String {};
else
this.parameterList = parameterList;
this.form = form;
addClickListener(event -> {
fireClickEvent(event);
});

addClickListener(this);
impl = new DynComponentImpl();

//boutton initially disable
this.setEnabled(isActif());


}









share|improve this question






















  • The first program that allows me to fill a valid field
    – woodson
    yesterday















up vote
0
down vote

favorite












I work with Vaadin. I have a text field and a button. My button is initially disabled. When my text field is filled with valid data my button must activate. I can not activate my button. Could you help me ? Thank you



public static DynTextField createFromElement(Element elt, DynForm form) {
if (elt.getNodeName().equals("param") && elt.getAttribute("type").equals("TEXT")) {
DynTextField dtf = new DynTextField();
dtf.setForm(form);
if (elt.hasAttribute("texte"))
dtf.setCaption(elt.getAttribute("texte"));
dtf.nom = elt.getAttribute("nom");
if (elt.hasAttribute("FORMAT"))
dtf.setFormat(elt.getAttribute("FORMAT"));
dtf.setDescription(elt.getAttribute("description"));
dtf.setStyleName("param" + (elt.hasAttribute("class") ? elt.getAttribute("class") : ""));
return dtf;
} else
return null;
}

private void setFormat(String attribute) {
binder = new Binder<>();
binder.forField(this).withValidator(new RegexpValidator("Saisie obligatoire !!", attribute)).asRequired("Format Erroné").bind(No.getter(), No.setter());
//new Binder<>().forField(this).withValidator(new RegexpValidator(attribute, "Format Erroné")).asRequired();

}

// convenience empty getter and setter implementation for better readability
public static class No {
public static <SOURCE, TARGET> ValueProvider<SOURCE, TARGET> getter() {
return source -> null;
}

public static <BEAN, FIELDVALUE> Setter<BEAN, FIELDVALUE> setter() {
return (bean, fieldValue) -> {
//no op
};
}
}


The program that creates my button. This is where I would like to make my button active.



public DynButton(DynForm form, String as400PGMName, String parameterList) {
super(VaadinIcons.CHECK);
this.as400PGMName = as400PGMName;
if (parameterList.length == 1 && parameterList[0].equals(""))
this.parameterList = new String {};
else
this.parameterList = parameterList;
this.form = form;
addClickListener(event -> {
fireClickEvent(event);
});

addClickListener(this);
impl = new DynComponentImpl();

//boutton initially disable
this.setEnabled(isActif());


}









share|improve this question






















  • The first program that allows me to fill a valid field
    – woodson
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I work with Vaadin. I have a text field and a button. My button is initially disabled. When my text field is filled with valid data my button must activate. I can not activate my button. Could you help me ? Thank you



public static DynTextField createFromElement(Element elt, DynForm form) {
if (elt.getNodeName().equals("param") && elt.getAttribute("type").equals("TEXT")) {
DynTextField dtf = new DynTextField();
dtf.setForm(form);
if (elt.hasAttribute("texte"))
dtf.setCaption(elt.getAttribute("texte"));
dtf.nom = elt.getAttribute("nom");
if (elt.hasAttribute("FORMAT"))
dtf.setFormat(elt.getAttribute("FORMAT"));
dtf.setDescription(elt.getAttribute("description"));
dtf.setStyleName("param" + (elt.hasAttribute("class") ? elt.getAttribute("class") : ""));
return dtf;
} else
return null;
}

private void setFormat(String attribute) {
binder = new Binder<>();
binder.forField(this).withValidator(new RegexpValidator("Saisie obligatoire !!", attribute)).asRequired("Format Erroné").bind(No.getter(), No.setter());
//new Binder<>().forField(this).withValidator(new RegexpValidator(attribute, "Format Erroné")).asRequired();

}

// convenience empty getter and setter implementation for better readability
public static class No {
public static <SOURCE, TARGET> ValueProvider<SOURCE, TARGET> getter() {
return source -> null;
}

public static <BEAN, FIELDVALUE> Setter<BEAN, FIELDVALUE> setter() {
return (bean, fieldValue) -> {
//no op
};
}
}


The program that creates my button. This is where I would like to make my button active.



public DynButton(DynForm form, String as400PGMName, String parameterList) {
super(VaadinIcons.CHECK);
this.as400PGMName = as400PGMName;
if (parameterList.length == 1 && parameterList[0].equals(""))
this.parameterList = new String {};
else
this.parameterList = parameterList;
this.form = form;
addClickListener(event -> {
fireClickEvent(event);
});

addClickListener(this);
impl = new DynComponentImpl();

//boutton initially disable
this.setEnabled(isActif());


}









share|improve this question













I work with Vaadin. I have a text field and a button. My button is initially disabled. When my text field is filled with valid data my button must activate. I can not activate my button. Could you help me ? Thank you



public static DynTextField createFromElement(Element elt, DynForm form) {
if (elt.getNodeName().equals("param") && elt.getAttribute("type").equals("TEXT")) {
DynTextField dtf = new DynTextField();
dtf.setForm(form);
if (elt.hasAttribute("texte"))
dtf.setCaption(elt.getAttribute("texte"));
dtf.nom = elt.getAttribute("nom");
if (elt.hasAttribute("FORMAT"))
dtf.setFormat(elt.getAttribute("FORMAT"));
dtf.setDescription(elt.getAttribute("description"));
dtf.setStyleName("param" + (elt.hasAttribute("class") ? elt.getAttribute("class") : ""));
return dtf;
} else
return null;
}

private void setFormat(String attribute) {
binder = new Binder<>();
binder.forField(this).withValidator(new RegexpValidator("Saisie obligatoire !!", attribute)).asRequired("Format Erroné").bind(No.getter(), No.setter());
//new Binder<>().forField(this).withValidator(new RegexpValidator(attribute, "Format Erroné")).asRequired();

}

// convenience empty getter and setter implementation for better readability
public static class No {
public static <SOURCE, TARGET> ValueProvider<SOURCE, TARGET> getter() {
return source -> null;
}

public static <BEAN, FIELDVALUE> Setter<BEAN, FIELDVALUE> setter() {
return (bean, fieldValue) -> {
//no op
};
}
}


The program that creates my button. This is where I would like to make my button active.



public DynButton(DynForm form, String as400PGMName, String parameterList) {
super(VaadinIcons.CHECK);
this.as400PGMName = as400PGMName;
if (parameterList.length == 1 && parameterList[0].equals(""))
this.parameterList = new String {};
else
this.parameterList = parameterList;
this.form = form;
addClickListener(event -> {
fireClickEvent(event);
});

addClickListener(this);
impl = new DynComponentImpl();

//boutton initially disable
this.setEnabled(isActif());


}






java vaadin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









woodson

12




12












  • The first program that allows me to fill a valid field
    – woodson
    yesterday


















  • The first program that allows me to fill a valid field
    – woodson
    yesterday
















The first program that allows me to fill a valid field
– woodson
yesterday




The first program that allows me to fill a valid field
– woodson
yesterday












1 Answer
1






active

oldest

votes

















up vote
4
down vote













You can do it with a listener on either the text field or the binder



textField.addValueChangeListener(e -> 
myButton.setEnabled(!e.getValue().equals("")));


or



binder.addStatusChangeListener(e -> 
myButton.setEnabled(!e.hasValidationErrors()));





share|improve this answer





















  • I did as you told me; it does not work. My button does not listen to my text fields. Here is my program : private DynTextField dtf1 = new DynTextField(); dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday






  • 1




    @woodson It should work, but you have to specify the button which should be enabled/disabled when text is entered in the text fields.
    – André Schild
    yesterday










  • this.setEnabled (isActif ()); allows me to disable my button. Here is my isActive program: private boolean isActive () { for (String param: parameterList) { if (! getForm (). getParam (param) .isValid ()) return false; } return true; } I do not see how to implement it
    – woodson
    yesterday












  • So this had to work : dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday










  • I tried this code it does not work. Someone could give me some advice: dtf1.addValueChangeListener(event -> { if(event.getValue().isEmpty()) this.setEnabled(isActif()); else this.setEnabled(isActif()); });
    – woodson
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204337%2fhow-to-enable-a-button-when-filling-a-textfield-with-vaadin%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote













You can do it with a listener on either the text field or the binder



textField.addValueChangeListener(e -> 
myButton.setEnabled(!e.getValue().equals("")));


or



binder.addStatusChangeListener(e -> 
myButton.setEnabled(!e.hasValidationErrors()));





share|improve this answer





















  • I did as you told me; it does not work. My button does not listen to my text fields. Here is my program : private DynTextField dtf1 = new DynTextField(); dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday






  • 1




    @woodson It should work, but you have to specify the button which should be enabled/disabled when text is entered in the text fields.
    – André Schild
    yesterday










  • this.setEnabled (isActif ()); allows me to disable my button. Here is my isActive program: private boolean isActive () { for (String param: parameterList) { if (! getForm (). getParam (param) .isValid ()) return false; } return true; } I do not see how to implement it
    – woodson
    yesterday












  • So this had to work : dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday










  • I tried this code it does not work. Someone could give me some advice: dtf1.addValueChangeListener(event -> { if(event.getValue().isEmpty()) this.setEnabled(isActif()); else this.setEnabled(isActif()); });
    – woodson
    yesterday















up vote
4
down vote













You can do it with a listener on either the text field or the binder



textField.addValueChangeListener(e -> 
myButton.setEnabled(!e.getValue().equals("")));


or



binder.addStatusChangeListener(e -> 
myButton.setEnabled(!e.hasValidationErrors()));





share|improve this answer





















  • I did as you told me; it does not work. My button does not listen to my text fields. Here is my program : private DynTextField dtf1 = new DynTextField(); dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday






  • 1




    @woodson It should work, but you have to specify the button which should be enabled/disabled when text is entered in the text fields.
    – André Schild
    yesterday










  • this.setEnabled (isActif ()); allows me to disable my button. Here is my isActive program: private boolean isActive () { for (String param: parameterList) { if (! getForm (). getParam (param) .isValid ()) return false; } return true; } I do not see how to implement it
    – woodson
    yesterday












  • So this had to work : dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday










  • I tried this code it does not work. Someone could give me some advice: dtf1.addValueChangeListener(event -> { if(event.getValue().isEmpty()) this.setEnabled(isActif()); else this.setEnabled(isActif()); });
    – woodson
    yesterday













up vote
4
down vote










up vote
4
down vote









You can do it with a listener on either the text field or the binder



textField.addValueChangeListener(e -> 
myButton.setEnabled(!e.getValue().equals("")));


or



binder.addStatusChangeListener(e -> 
myButton.setEnabled(!e.hasValidationErrors()));





share|improve this answer












You can do it with a listener on either the text field or the binder



textField.addValueChangeListener(e -> 
myButton.setEnabled(!e.getValue().equals("")));


or



binder.addStatusChangeListener(e -> 
myButton.setEnabled(!e.hasValidationErrors()));






share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Tazavoo

598210




598210












  • I did as you told me; it does not work. My button does not listen to my text fields. Here is my program : private DynTextField dtf1 = new DynTextField(); dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday






  • 1




    @woodson It should work, but you have to specify the button which should be enabled/disabled when text is entered in the text fields.
    – André Schild
    yesterday










  • this.setEnabled (isActif ()); allows me to disable my button. Here is my isActive program: private boolean isActive () { for (String param: parameterList) { if (! getForm (). getParam (param) .isValid ()) return false; } return true; } I do not see how to implement it
    – woodson
    yesterday












  • So this had to work : dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday










  • I tried this code it does not work. Someone could give me some advice: dtf1.addValueChangeListener(event -> { if(event.getValue().isEmpty()) this.setEnabled(isActif()); else this.setEnabled(isActif()); });
    – woodson
    yesterday


















  • I did as you told me; it does not work. My button does not listen to my text fields. Here is my program : private DynTextField dtf1 = new DynTextField(); dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday






  • 1




    @woodson It should work, but you have to specify the button which should be enabled/disabled when text is entered in the text fields.
    – André Schild
    yesterday










  • this.setEnabled (isActif ()); allows me to disable my button. Here is my isActive program: private boolean isActive () { for (String param: parameterList) { if (! getForm (). getParam (param) .isValid ()) return false; } return true; } I do not see how to implement it
    – woodson
    yesterday












  • So this had to work : dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
    – woodson
    yesterday










  • I tried this code it does not work. Someone could give me some advice: dtf1.addValueChangeListener(event -> { if(event.getValue().isEmpty()) this.setEnabled(isActif()); else this.setEnabled(isActif()); });
    – woodson
    yesterday
















I did as you told me; it does not work. My button does not listen to my text fields. Here is my program : private DynTextField dtf1 = new DynTextField(); dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
– woodson
yesterday




I did as you told me; it does not work. My button does not listen to my text fields. Here is my program : private DynTextField dtf1 = new DynTextField(); dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
– woodson
yesterday




1




1




@woodson It should work, but you have to specify the button which should be enabled/disabled when text is entered in the text fields.
– André Schild
yesterday




@woodson It should work, but you have to specify the button which should be enabled/disabled when text is entered in the text fields.
– André Schild
yesterday












this.setEnabled (isActif ()); allows me to disable my button. Here is my isActive program: private boolean isActive () { for (String param: parameterList) { if (! getForm (). getParam (param) .isValid ()) return false; } return true; } I do not see how to implement it
– woodson
yesterday






this.setEnabled (isActif ()); allows me to disable my button. Here is my isActive program: private boolean isActive () { for (String param: parameterList) { if (! getForm (). getParam (param) .isValid ()) return false; } return true; } I do not see how to implement it
– woodson
yesterday














So this had to work : dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
– woodson
yesterday




So this had to work : dtf1.addValueChangeListener(event -> this.setEnabled(isActif()));
– woodson
yesterday












I tried this code it does not work. Someone could give me some advice: dtf1.addValueChangeListener(event -> { if(event.getValue().isEmpty()) this.setEnabled(isActif()); else this.setEnabled(isActif()); });
– woodson
yesterday




I tried this code it does not work. Someone could give me some advice: dtf1.addValueChangeListener(event -> { if(event.getValue().isEmpty()) this.setEnabled(isActif()); else this.setEnabled(isActif()); });
– woodson
yesterday


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204337%2fhow-to-enable-a-button-when-filling-a-textfield-with-vaadin%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)