Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bcda139b

Von Sven Schöling vor etwa 7 Jahren hinzugefügt

  • ID bcda139b21ae2827e5245d00ba85d1b95d861b93
  • Vorgänger 3f264030
  • Nachfolger a536d0ec

kivi.Validator: check_right_[number|date]_format entfernt

Unterschiede anzeigen:

js/common.js
10 10
  return string;
11 11
}
12 12

  
13
function check_right_number_format(input_name) {
14
  var decpoint = kivi._number_format.decimalSep;
15
  var thpoint  = kivi._number_format.thousandSep;
16

  
17
  var test_val = input_name.value;
18
  if(thpoint && thpoint == ','){
19
    test_val = test_val.replace(/,/g, '');
20
  }
21
  if(thpoint && thpoint == '.'){
22
    test_val = test_val.replace(/\./g, '');
23
  }
24
  if(thpoint && thpoint == "'"){
25
    test_val = test_val.replace(/\'/g, '');
26
  }
27
  if(decpoint && decpoint == ','){
28
    test_val = test_val.replace(/,/g, '.');
29
  }
30
  var forbidden = test_val.match(/[^\s\d\(\)\-\+\*\/\.]/g);
31
  if (forbidden && forbidden.length > 0 ){
32
    return annotate(input_name, kivi.t8('wrongformat'), kivi.myconfig.numberformat);
33
  }
34

  
35
  try{
36
    eval(test_val);
37
  }catch(err){
38
    return annotate(input_name, kivi.t8('wrongformat'), kivi.myconfig.numberformat);
39
  }
40

  
41
  return annotate(input_name);
42
}
43

  
44
function check_right_date_format(input_name) {
45
  if(input_name.value == "") {
46
    annotate(input_name);
47
    return true;
48
  }
49

  
50
  var dateFormat = kivi.myconfig.dateformat;
51
  var seperator  = kivi._date_format.sep;
52

  
53
  if ( ( input_name.value.match(/^\d+$/ ) ) && !(dateFormat.lastIndexOf("y") == 3) ) {
54
    // date shortcuts for entering date without separator for three date styles, e.g.
55
    // 31122014 -> 12.04.2014
56
    // 12312014 -> 12/31/2014
57
    // 31122014 -> 31/12/2014
58

  
59
    if (input_name.value.match(/^\d{8}$/)) {
60
      input_name.value = input_name.value.replace(/^(\d\d)(\d\d)(\d\d\d\d)$/, "$1" + seperator + "$2" + seperator + "$3")
61
    } else if (input_name.value.match(/^\d{6}$/)) {
62
      // 120414 -> 12.04.2014
63
      input_name.value = input_name.value.replace(/^(\d\d)(\d\d)(\d\d)$/, "$1" + seperator + "$2" + seperator + "$3")
64
    } else if (input_name.value.match(/^\d{4}$/)) {
65
      // 1204 -> 12.04.2014
66
      var today = new Date();
67
      var year = today.getYear();
68
      if (year < 999) year += 1900;
69
      input_name.value = input_name.value.replace(/^(\d\d)(\d\d)$/, "$1" + seperator + "$2");
70
      input_name.value = input_name.value + seperator + year;
71
    } else  if ( input_name.value.match(/^\d{1,2}$/ ) ) {
72
      // assume the entry is the day of the current month and current year
73
      var today = new Date();
74
      var day = input_name.value;
75
      var month = today.getMonth() + 1;
76
      var year = today.getYear();
77
      if( day.length == 1 && day < 10) {
78
        day='0'+day;
79
      };
80
      if(month<10) {
81
        month='0'+month;
82
      };
83
      if (year < 999) year += 1900;
84
      if ( dateFormat.lastIndexOf("d") == 1) {
85
        input_name.value = day + seperator + month + seperator + year;
86
      } else {
87
        input_name.value = month + seperator + day + seperator + year;
88
      }
89
    };
90
  }
91

  
92
  var matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + "\$","ig");
93
  if(!(dateFormat.lastIndexOf("y") == 3) && !matching.test(input_name.value)) {
94
    matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + '\\d\\d\$', "ig");
95
    if(!matching.test(input_name.value)) {
96
      return annotate(input_name, kivi.t8('Falsches Datumsformat!'), kivi.myconfig.dateformat);
97
    }
98
  }
99
  else {
100
    if (dateFormat.lastIndexOf("y") == 3 && !matching.test(input_name.value)) {
101
      return annotate(input_name, kivi.t8('Falsches Datumsformat!'), kivi.myconfig.dateformat);
102
    }
103
  }
104
  return annotate(input_name);
105
}
106

  
107
function annotate(input_name, error, expected) {
108
  var $e = $(input_name);
109
  if (error) {
110
    $e.addClass('kivi-validator-invalid');
111
    var tooltip = error + ' (' + expected + ')';
112
    if ($e.hasClass('tooltipstered'))
113
      $e.tooltipster('destroy');
114

  
115
    $e.tooltipster({
116
      content: tooltip,
117
      theme: 'tooltipster-light',
118
    });
119
    $e.tooltipster('show');
120
  } else {
121
    $e.removeClass('kivi-validator-invalid');
122
    if ($e.hasClass('tooltipstered'))
123
      $e.tooltipster('destroy');
124
  }
125
}
126

  
127 13
function get_input_value(input_name) {
128 14
  var the_input = document.getElementsByName(input_name);
129 15
  if (the_input && the_input[0])
js/kivi.js
363 363
  };
364 364

  
365 365
  // Return a function object by its name (a string). Works both with
366
  // global functions (e.g. "check_right_date_format") and those in
367
  // namespaces (e.g. "kivi.t8").
366
  // global functions (e.g. "focus_by_name") and those in namespaces (e.g.
367
  // "kivi.t8").
368 368
  // Returns null if the object is not found.
369 369
  ns.get_function_by_name = function(name) {
370 370
    var parts = name.match("(.+)\\.([^\\.]+)$");

Auch abrufbar als: Unified diff