LSform/LSformElement : permit form element to provide custom clean value method
[ldapsaisie.git] / public_html / includes / js / LSformElement_field.js
1 var LSformElement_field = new Class({
2     initialize: function(LSformElement,li,id,field_name){
3       this.id = id;
4       this.LSformElement = LSformElement;
5       this.li = li;
6       this.field_name = field_name;
7       
8       if (this.LSformElement.multiple) {
9         this.addFieldBtn = new Element('img');
10         this.addFieldBtn.src = varLSdefault.imagePath('add');
11         this.addFieldBtn.addClass('btn');
12         this.addFieldBtn.addEvent('click',this.LSformElement.onAddFieldBtnClick.bind(this.LSformElement,this));
13         this.addFieldBtn.injectInside(this.li);
14         varLSdefault.addHelpInfo(this.addFieldBtn,'LSform','addFieldBtn');
15         
16         this.removeFieldBtn = new Element('img');
17         this.removeFieldBtn.src = varLSdefault.imagePath('remove');
18         this.removeFieldBtn.addClass('btn');
19         this.removeFieldBtn.addEvent('click',this.LSformElement.onRemoveFieldBtnClick.bind(this.LSformElement,this));
20         this.removeFieldBtn.injectInside(this.li);
21         varLSdefault.addHelpInfo(this.removeFieldBtn,'LSform','removeFieldBtn');
22       }
23     },
24     
25     getFormField: function() {
26       if ($type(this._formField)) {
27         return this._formField;
28       }
29       this._formField = this.li.getFirst('input');
30       if(!$type(this._formField)) {
31         this._formField = this.li.getFirst('textarea');
32       }
33       return this._formField;
34     },
35     
36     clearValue: function() {
37       if ($type(this.getFormField())) {
38         this.getFormField().value='';
39       }
40       varLSform.clearFieldValue(this.field_name);
41     },
42     
43     remove: function() {
44       this.li.destroy();
45     }
46 });