Skip to content

Instantly share code, notes, and snippets.

View MaxMorais's full-sized avatar
🏢
Building Solutions in Tech

Maxwell Morais MaxMorais

🏢
Building Solutions in Tech
View GitHub Profile
@MaxMorais
MaxMorais / maskedinput.py
Last active December 11, 2015 04:59
Web2py MaskedInput Widget
# This widget requires jQuery-iMask to run
#https://github.com/cwolves/jQuery-iMask
from gluon.dal import Field
import re
def factory(mask='', auto_start=True, empty_chr="_", error_message="Did not match!"):
assert len(mask)>1, 'empty mask not is allowed'
assert len(empty_chr)==1, 'empty_chr requires one character'
from gluon.sqlhtml import StringWidget
from gluon.validators import IS_MATCH, IS_NOT_EMPTY
// add a trigger on field "custom_field1"
cur_frm.cscript.custom_field1 = function(doc, cdt, cdn) {
// update a new field "custom_field3"
doc.custom_field3 = flt(doc.custom_field1)*flt(doc.custom_field2)/1000;
// refresh in form
refresh_field('custom_field3');
}