[freeside-commits] freeside/httemplate/view/cust_main
quick-charge.html, 1.5, 1.6
Ivan,,,
ivan at wavetail.420.am
Fri Dec 8 05:36:09 PST 2006
Update of /home/cvs/cvsroot/freeside/httemplate/view/cust_main
In directory wavetail:/tmp/cvs-serv30128/view/cust_main
Modified Files:
quick-charge.html
Log Message:
some javascript validation magic to give one-time charges better UI
Index: quick-charge.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/view/cust_main/quick-charge.html,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- quick-charge.html 23 Aug 2006 22:25:39 -0000 1.5
+++ quick-charge.html 8 Dec 2006 13:36:06 -0000 1.6
@@ -1,19 +1,73 @@
-%
-% my( $cust_main ) = @_;
-%
+<SCRIPT TYPE="text/javascript">
+function enable_quick_charge () {
+ //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+ if ( document.QuickChargeForm.amount.value
+ && document.QuickChargeForm.pkg.value ) {
+ document.QuickChargeForm.submit.disabled = false;
+ } else {
+ document.QuickChargeForm.submit.disabled = true;
+ }
+}
-<FORM ACTION="<%$p%>edit/process/quick-charge.cgi" METHOD="POST">
+function enable_quick_charge_desc () {
+ //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+ if ( document.QuickChargeForm.amount.value ) {
+ document.QuickChargeForm.submit.disabled = false;
+ } else {
+ document.QuickChargeForm.submit.disabled = true;
+ }
+}
+
+function enable_quick_charge_amount () {
+ //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+ if ( document.QuickChargeForm.pkg.value ) {
+ document.QuickChargeForm.submit.disabled = false;
+ } else {
+ document.QuickChargeForm.submit.disabled = true;
+ }
+}
+
+function validate_quick_charge () {
+ //alert('validate_quick_charge');
+ var pkg = document.QuickChargeForm.pkg.value;
+ var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/ ;
+ var amount = document.QuickChargeForm.amount.value;
+ var amount_regex = /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ;
+
+ if ( amount_regex.test(amount) && pkg_regex.test(pkg) ) {
+ return true;
+ } else if ( amount_regex.test(amount) ) {
+ if ( pkg ) {
+ alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
+ } else {
+ alert('Enter a description for the one-time charge');
+ }
+ return false;
+ } else {
+ alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
+ return false;
+ }
+}
+
+</SCRIPT>
+
+<FORM NAME="QuickChargeForm" ACTION="<%$p%>edit/process/quick-charge.cgi" METHOD="POST" onSubmit="return validate_quick_charge()">
<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main->custnum %>">
-Description:<INPUT TYPE="text" NAME="pkg">
+Description:<INPUT TYPE="text" NAME="pkg" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge_desc()">
-Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>
+Amount:<INPUT TYPE="text" NAME="amount" SIZE=6 onChange="enable_quick_charge()" onKeyPress="enable_quick_charge_amount()">
<% include('/elements/select-taxclass.html') %>
-<INPUT TYPE="submit" VALUE="One-time charge">
+<INPUT NAME="submit" TYPE="submit" VALUE="One-time charge" DISABLED>
</FORM>
+<%init>
+
+my( $cust_main ) = @_;
+
+</%init>
More information about the freeside-commits
mailing list