/
required.jsc
95 lines (87 loc) · 2.11 KB
/
required.jsc
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
# Copyright 2005-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: required.jsc,v 1.4 2007-03-30 23:40:48 pajamian Exp $
CodeDef required JavaScriptCheck 1
CodeDef required Description Javascript non-blank check
CodeDef required Help Also checks for only whitespace
CodeDef required Routine <<EOR
sub {
my $opt = shift;
use vars qw/$Tag/;
my $name = $opt->{name};
my $fn = $opt->{form_name} || 'flex_editor';
my $rn = $opt->{js_check_name} || "${fn}_${name}_required";
my $lab = $opt->{label};
$lab ||= $name;
my $exist = $opt->{prepend} || '';
my $undef_message = $Tag->jsq(
errmsg(
"%s (%s): requires entry, currently %s",
$lab, $name, errmsg('undefined'),
)
);
my $blank_message = $Tag->jsq(
errmsg(
"%s (%s): requires entry, currently %s",
$lab, $name, errmsg('blank'),
)
);
my $whitespace_message = $Tag->jsq(
errmsg(
"%s (%s): requires entry, currently %s",
$lab, $name, errmsg('whitespace'),
)
);
my $script = <<EOS;
<script>
function $rn (el, frm) {
var nm = el.name;
if(el.value == undefined) {
alert($undef_message);
return false;
}
if(el.value.length == 0) {
alert($blank_message);
return false;
}
if(el.value.match(/^\\s*\$/)) {
alert($whitespace_message);
return false;
}
return true;
}
</script>
EOS
if($exist) {
$opt->{prepend} = "$script\n$exist";
}
else {
$opt->{prepend} = $script;
}
my $call = "$rn(this,this.form)";
if(my $ejs = $opt->{js}) {
if($ejs =~ s{(^|\s+)onchange\s*=\s*"(.*)"}{
my $pre = $1;
my $ex = $2;
qq[${pre}onBlur="if($call) { $ex }"];
}ie
)
{
$opt->{js} = $ejs;
}
else {
$opt->{js} =~ s/\s+$//;
$opt->{js} .= qq{ onBlur="$call"};
}
}
else {
$opt->{js} = qq{ onBlur="$call"};
}
return;
}
EOR