IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Ext JS / Sencha Discussion :

valeur par défaut dans un textfield


Sujet :

Ext JS / Sencha

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 39
    Par défaut valeur par défaut dans un textfield
    Bonjour,

    J'ai un formulaire constitué de trois listes déroulantes et de deux datefield un pour une date de début et l'autre pour une date de fin.

    Je voudrais que dans la date de début en valeur par défaut soit le premier jour du mois et en fin le dernier. J'ai essayé de remplir l'attribut 'value' ça marche pour un mais si j'en mets deux --> erreur.

    J'ai repris l'exemple d'extJS sur les vtype.

    Voici le code de ma partie formulaire :
    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
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    	//on créer le formulaire
    	echo "<script type='text/javascript'>
    	/*!
    	 * Ext JS Library 3.1.1
    	 * Copyright(c) 2006-2010 Ext JS, LLC
    	 * licensing@extjs.com
    	 * http://www.extjs.com/license
    	 */
     
    	// Add the additional 'advanced' VTypes
    	Ext.apply(Ext.form.VTypes, {
        daterange : function(val, field) {
            var date = field.parseDate(val);
     
            if(!date){
                return false;
            }
            if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
                var start = Ext.getCmp(field.startDateField);
                start.setMaxValue(date);
                start.validate();
                this.dateRangeMax = date;
            }
            else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
                var end = Ext.getCmp(field.endDateField);
                end.setMinValue(date);
                end.validate();
                this.dateRangeMin = date;
            }
            /*
             * Always return true since we're only using this vtype to set the
             * min/max allowed values (these are tested for after the vtype test)
             */
            return true;
        }
    	});
     
    	Ext.onReady(function()
    		{
    		/**
    		 * Handler specified for the 'Available' column renderer
    		 * @param {Object} value
    		 */
     
    		function formatDate(value)
    			{
    			return value ? value.dateFormat('M d, Y') : '';
    			}
     
    		// shorthand alias
    		var fm = Ext.form;
     
    		//create Data Store for ComboBox and create ComboBox
    		var storeProject = new Ext.data.Store({
    			// destroy the store if the grid is destroyed
    			autoDestroy: true,
    			autoLoad: true,
    			// load remote data using HTTP
    			url: './includes/project_RptPj.php',
     
    			// specify a XmlReader (coincides with the XML Ext.format of the returned data)
    			reader: new Ext.data.XmlReader({
    				// records will have a 'project' tag
    				record: 'project',
    				// use an Array of field definition objects to implicitly create a Record constructor
    				fields: [
    					{name: 'projectId'},
    					{name: 'projectName'}					
    					]
    				}),
    			sortInfo: {field:'projectId', direction:'ASC'}
    			});
     
    		var storeDiscipline = new Ext.data.Store({
    			// destroy the store if the grid is destroyed
    			autoDestroy: true,
    			autoLoad: false,
    			// load remote data using HTTP
    			url: './includes/discipline_RptPj.php',
     
    			// specify a XmlReader (coincides with the XML Ext.format of the returned data)
    			reader: new Ext.data.XmlReader({
    				// records will have a 'discipline' tag
    				record: 'discipline',
    				// use an Array of field definition objects to implicitly create a Record constructor
    				fields: [
    					{name: 'disciplineId'},
    					{name: 'disciplineName'}					
    				]
    			}),
    			sortInfo: {field:'disciplineId', direction:'ASC'}
    			});			
     
    		var storeSociete = new Ext.data.Store({
    			// destroy the store if the grid is destroyed
    			autoDestroy: true,
    			autoLoad: false,
    			// load remote data using HTTP
    			url: './includes/societe_RptPj.php',
     
    			// specify a XmlReader (coincides with the XML Ext.format of the returned data)
    			reader: new Ext.data.XmlReader({
    				// records will have a 'societe' tag
    				record: 'societe',
    				// use an Array of field definition objects to implicitly create a Record constructor
    				fields: [
    					{name: 'societeId'},
    					{name: 'societeName'}					
    				]
    			}),
    			sortInfo: {field:'societeId', direction:'ASC'}
    			});				
     
    		var comboSociete = new Ext.form.ComboBox({
    			allowBlank: false,
    			lazyRender: true,
    			maxLength: 55,
    			width: 110,			
    			editable: false,
    			emptyText: 'Select a company',	
    			mode: 'local',
    			triggerAction: 'all',
    			store: storeSociete,
    			valueField: 'societeId',
    			displayField: 'societeId',
    			fieldLabel: 'Company ',
    			name: 'selectSte'	
    			});
     
    		var comboDiscipline = new Ext.form.ComboBox({
    			allowBlank: false,
    			lazyRender: true,
    			maxLength: 55,
    			width: 110,			
    			editable: false,
    			emptyText: 'Select a discipline',	
    			mode: 'local',
    			triggerAction: 'all',
    			store: storeDiscipline,
    			valueField: 'disciplineId',
    			displayField: 'disciplineId',
    			fieldLabel: 'Discipline ',
    			name: 'selectDisc',	
    			listeners: {
    			   'select' : function(cmb, rec, idx) {
    				   comboSociete.clearValue();
    				   comboSociete.store.load({
    						params: {'project': comboProject.getValue(), 'discipline': comboDiscipline.getValue()}
    						});		   
    					}
    				}		
    			});			
     
    		var comboProject = new Ext.form.ComboBox({
    			allowBlank: false,
    			lazyRender: true,
    			maxLength: 55,
    			width: 110,		
    			editable: false,
    			emptyText: 'Select a project',		
    			mode: 'local',
    			triggerAction: 'all',
    			store: storeProject,
    			valueField: 'projectId',
    			displayField: 'projectId',
    			fieldLabel: 'Project ',
    			name: 'selectPj',			
    			listeners: {
    			   'select' : function(cmb, rec, idx) {
    				   comboDiscipline.clearValue();
    				   comboDiscipline.store.load({
    						params: {'project': comboProject.getValue() }
    						});		   
    					}
    				}		
    			});
     
    		function  fct_submit() {
    			formRptPj.form.submit({
    				url: 'index.php?page=rapport_projet',
    				method: 'GET'
    				});
    			};
     
    		var formRptPj = new Ext.FormPanel({
    			labelWidth: 75, // label settings here cascade unless overridden
    			standardSubmit: true,
    			url:'index.php?page=rapport_projet',
    			renderTo:'formRptPj',
    			frame:true,
    			title: '...',
    			bodyStyle:'padding:5px 5px 0',
    			width: 350,
    			defaults: {width: 230},
    			defaultType: 'textfield',
    			items: [comboProject,comboDiscipline,comboSociete,{
    				xtype:'fieldset',
    				title: 'During',
    				collapsible: true,
    				autoHeight:true,
    				autoWidth:true,
    				defaults: {width: 215},
    				defaultType: 'datefield',
    				items :[{
    					fieldLabel: 'Start Date',
    					name: 'startdt',
    					id: 'startdt',
    					vtype: 'daterange',
    					endDateField: 'enddt' // id of the end date field
    				},{
    					fieldLabel: 'End Date',
    					name: 'enddt',
    					id: 'enddt',	
    					vtype: 'daterange',
    					startDateField: 'startdt' // id of the start date field
    				}]}
    				],
    			buttons: [{
    				text: 'Validate',
    				handler : fct_submit
    				}]
    			});
     
    		});
    	</script>";
     
    	//maintenant on s'occupe d'affiche le tout
    	echo '<div id="formRptPj"></div>';
    Merci de votre aide, bonne journée.

  2. #2
    Membre chevronné
    Profil pro
    Inscrit en
    Février 2010
    Messages
    267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 267
    Par défaut
    bonjour,
    tu devrais faire un copier coller de l'exemple ... vtypes

    il est plutot bien ... et repond a ta problematique ...

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 39
    Par défaut
    Bonjour,

    Justement c'est ce que j'ai fais, le seul changement au code d'origine c'est que j'ai mis les éléments dans un fieldLabel.

  4. #4
    Membre chevronné
    Profil pro
    Inscrit en
    Février 2010
    Messages
    267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 267
    Par défaut
    bonjour, ton code sembles fonctionner ...

    essayes de regrouper ta balise script et ton div ...

    echo '<script></script><div id="formRptPj"></div>';

    je te joins ton code ... dans lequel j'ai desactiver certains elements ...


    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
     		var dr = new Ext.FormPanel({
    			labelWidth: 75, // label settings here cascade unless overridden
    			standardSubmit: true,
    			url:'index.php?page=rapport_projet',
    		//	renderTo:'formRptPj',
    			frame:true,
    			title: '...',
    			bodyStyle:'padding:5px 5px 0',
    			width: 350,
    			defaults: {width: 230},
    			defaultType: 'textfield',
    			items: [{
    				xtype:'fieldset',
    				title: 'During',
    				collapsible: true,
    				autoHeight:true,
    				autoWidth:true,
    				defaults: {width: 215},
    				defaultType: 'datefield',
    				items :[{
    					fieldLabel: 'Start Date',
    					name: 'startdt',
    					id: 'startdt',
    					vtype: 'daterange',
    					endDateField: 'enddt' // id of the end date field
    				},{
    					fieldLabel: 'End Date',
    					name: 'enddt',
    					id: 'enddt',	
    					vtype: 'daterange',
    					startDateField: 'startdt' // id of the start date field
    				}]}
    				]
    			});

  5. #5
    Membre chevronné
    Profil pro
    Inscrit en
    Février 2010
    Messages
    267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 267
    Par défaut
    ah oui ...


    essayes de faire ...

    Ext.getCmp('startdt').setValue('10/10/2010');
    Ext.getCmp('endtdt').setValue('15/10/2010');

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 39
    Par défaut
    Oups, désolé chef j'avais oublié de dire que le script tournait très bien.

    En tout cas merci, j'ai mes valeurs par défauts dans les deux champs, parfait.

    Bonne fin d'après-midi.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Valeur par défaut dans un ALTER TABLE
    Par HULK dans le forum Langage SQL
    Réponses: 11
    Dernier message: 27/12/2005, 10h04
  2. Valeur par défaut dans un DbLookupCombobox
    Par defluc dans le forum Bases de données
    Réponses: 2
    Dernier message: 22/09/2005, 14h04
  3. [Débutant(e)]valeur par défaut dans méthodes
    Par seiryujay dans le forum Langage
    Réponses: 3
    Dernier message: 13/07/2005, 12h02
  4. Sélection valeur par défaut dans une zone de liste
    Par Cécile154 dans le forum IHM
    Réponses: 2
    Dernier message: 15/02/2005, 18h20
  5. Valeur par défaut dans une table objet
    Par Ricky81 dans le forum Oracle
    Réponses: 12
    Dernier message: 18/03/2004, 11h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo