Je travaille sur un projet web, j’utilise le framework ExtJS (ainsi que struts et spring). Je débute en JS et je n’arrive pas à faire ce que je souhaite...
Voilà, j’ai un formulaire qui utilise un DateField, l’utilisateur doit saisir une date et après je souhaite vérifier si la date est valide. Pour cela, ExtJs met à ma disposition une méthode utilisable sur les DateField qui permet de valider celle-ci : « isValid( Boolean preventMark ) : Boolean
Returns whether or not the field value is currently valid”.
Je n’arrive pas à utiliser cette méthode, j’ai essayé plusieurs choses mais à chaque fois ça ne fonctionne pas. Je ne dois pas l'appliquer à la bonne variable...
Petite remarque, je n'utilise pas la méthode submit classique du formulaire car j'ai crée une méthode qui me permet de ne mettre à jour qu'une partie de ma page (alors que le submit classique me met à jour toute ma page).
Voici mon code :
Page jsp
Page JS
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <html> <head> </head> <body> <br><input id="contextPath" type="hidden" value="<%=request.getContextPath()%>"/> <html:form styleId="jourForm" action="/compte.do"> <table class="tableForm"> <tr> <td class="tdright"><bean:message key="ce.dateExploit" /></td> <td class="tdpad"> <html:text styleId="dateExploit" property="dateExploitation" ></html:text> </td> <td> <html:button styleId="submitButton" property="submitButton" value="Valider" onclick="CompteExp.consultSubmitForm(dateExploit,'jourForm','/compte.do',false,compte.init)"> </html:button> </td> <tr> </table> </html:form> </body> </html>
Par exemple, je n’arrive pas à accéder à ma variable « dateExp » de la classe CompteExp dans ma fonction consultSubmitForm…-> J'ai testé if (this.dateExp.isValid) mais il ne me trouve pas ma variable.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 Ext.BLANK_IMAGE_URL = "../extjs/resources/images/default/s.gif"; var CompteExp = function(){ var dateExp ; return { init : function(){ this.dateExp = new Ext.form.DateField({ fieldLabel: 'Date Exploit', name: 'dateExploitation', width:100, format : 'd/m/Y', allowBlank:false, invalidText : 'Le format de la date n\'est pas correct.', applyTo : 'dateExploit' }); this.dateExp.altFormats = "d/m/Y|d-m-y|d-m-Y|d/m|d-m|dm|dmy|dmY|d"; }, consultSubmitForm : function (dateExploit, form, urlCible,resetForm,fctInitialisation){ if(dateExploit.isValid(false)){ Ext.Msg.alert('Erreur de saisie','La date n\'est pas valide.'); } else { Ce.submitForm(form,urlCible,resetForm,fctInitialisation); } } }; }();
C’est sûrement normal mais la je suis bloquée, si qqn pouvait me venir en aide. Il y a sûrement des choses que je fais mal mais là je bloque !
Merci d’avance![]()
Partager