webgui/www/extras/yui-ext/docs/overview-summary-NumberEditor.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

203 lines
11 KiB
HTML

<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
parent.document.title="NumberEditor.js Overview";
}
</script>
</head>
<body bgcolor="white" onload="asd();" style="margin:15px;">
<center>
<h2>NumberEditor.js</h2>
</center>
<h4>Summary</h4>
<p>
</p>
<table border="1" cellpadding="3" cellspacing="0" width="100%">
<tr bgcolor="#CCCCFF" class="TableHeadingColor">
<td colspan="2" class="title-cell">
<b>Class Summary</b>
</td>
</tr>
<tr bgcolor="white" class="TableRowColor">
<td width="15%"><b><a href="YAHOO.ext.grid.NumberEditor.html">YAHOO.ext.grid.NumberEditor</a></b></td>
<td>&nbsp;</td>
</tr>
</table>
<hr/>
<!-- ========== METHOD SUMMARY =========== -->
<!-- ========== END METHOD SUMMARY =========== -->
<pre class="sourceview">YAHOO.ext.grid.NumberEditor = <span class="reserved">function</span>(config){
var element = document.createElement(<span class="literal">'input'</span>);
element.type = <span class="literal">'text'</span>;
element.className = <span class="literal">'ygrid-editor ygrid-num-editor'</span>;
element.setAttribute(<span class="literal">'autocomplete'</span>, <span class="literal">'off'</span>);
document.body.appendChild(element);
YAHOO.ext.grid.NumberEditor.superclass.constructor.call(<span class="reserved">this</span>, element);
YAHOO.ext.util.Config.apply(<span class="reserved">this</span>, config);
};
YAHOO.extendX(YAHOO.ext.grid.NumberEditor, YAHOO.ext.grid.CellEditor);
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.initEvents = <span class="reserved">function</span>(){
var stopOnEnter = <span class="reserved">function</span>(e){
<span class="reserved">if</span>(e.browserEvent.keyCode == e.RETURN){
<span class="reserved">this</span>.stopEditing(true);
}
};
var allowed = <span class="literal">"0123456789"</span>;
<span class="reserved">if</span>(<span class="reserved">this</span>.allowDecimals){
allowed += <span class="reserved">this</span>.decimalSeparator;
}
<span class="reserved">if</span>(<span class="reserved">this</span>.allowNegative){
allowed += <span class="literal">'-'</span>;
}
var keyPress = <span class="reserved">function</span>(e){
var c = e.getCharCode();
<span class="reserved">if</span>(c != e.BACKSPACE &amp;&amp; allowed.indexOf(String.fromCharCode(c)) === -1){
e.stopEvent();
}
};
<span class="reserved">this</span>.element.mon(<span class="literal">'keydown'</span>, stopOnEnter, <span class="reserved">this</span>, true);
var vtask = new YAHOO.ext.util.DelayedTask(<span class="reserved">this</span>.validate, <span class="reserved">this</span>);
<span class="reserved">this</span>.element.mon(<span class="literal">'keyup'</span>, vtask.delay.createDelegate(vtask, [<span class="reserved">this</span>.validationDelay]));
<span class="reserved">this</span>.element.mon(<span class="literal">'keypress'</span>, keyPress, <span class="reserved">this</span>, true);
<span class="reserved">this</span>.element.on(<span class="literal">'blur'</span>, <span class="reserved">this</span>.stopEditing, <span class="reserved">this</span>, true);
};
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.validate = <span class="reserved">function</span>(){
var dom = <span class="reserved">this</span>.element.dom;
var value = dom.value;
<span class="reserved">if</span>(value.length &lt; 1){ <span class="comment">// if it's blank</span>
<span class="reserved">if</span>(<span class="reserved">this</span>.allowBlank){
dom.title = <span class="literal">''</span>;
<span class="reserved">this</span>.element.removeClass(<span class="literal">'ygrid-editor-invalid'</span>);
<span class="reserved">return</span> true;
}<span class="reserved">else</span>{
dom.title = <span class="reserved">this</span>.blankText;
<span class="reserved">this</span>.element.addClass(<span class="literal">'ygrid-editor-invalid'</span>);
<span class="reserved">return</span> false;
}
}
<span class="reserved">if</span>(value.search(/\d+/) === -1){
dom.title = <span class="reserved">this</span>.nanText.replace(<span class="literal">'%0'</span>, value);
<span class="reserved">this</span>.element.addClass(<span class="literal">'ygrid-editor-invalid'</span>);
<span class="reserved">return</span> false;
}
var num = <span class="reserved">this</span>.parseValue(value);
<span class="reserved">if</span>(num &lt; <span class="reserved">this</span>.minValue){
dom.title = <span class="reserved">this</span>.minText.replace(<span class="literal">'%0'</span>, <span class="reserved">this</span>.minValue);
<span class="reserved">this</span>.element.addClass(<span class="literal">'ygrid-editor-invalid'</span>);
<span class="reserved">return</span> false;
}
<span class="reserved">if</span>(num &gt; <span class="reserved">this</span>.maxValue){
dom.title = <span class="reserved">this</span>.maxText.replace(<span class="literal">'%0'</span>, <span class="reserved">this</span>.maxValue);
<span class="reserved">this</span>.element.addClass(<span class="literal">'ygrid-editor-invalid'</span>);
<span class="reserved">return</span> false;
}
var msg = <span class="reserved">this</span>.validator(value);
<span class="reserved">if</span>(msg !== true){
dom.title = msg;
<span class="reserved">this</span>.element.addClass(<span class="literal">'ygrid-editor-invalid'</span>);
<span class="reserved">return</span> false;
}
dom.title = <span class="literal">''</span>;
<span class="reserved">this</span>.element.removeClass(<span class="literal">'ygrid-editor-invalid'</span>);
<span class="reserved">return</span> true;
};
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.show = <span class="reserved">function</span>(){
<span class="reserved">this</span>.element.dom.title = <span class="literal">''</span>;
YAHOO.ext.grid.NumberEditor.superclass.show.call(<span class="reserved">this</span>);
<span class="reserved">if</span>(<span class="reserved">this</span>.selectOnFocus){
try{
<span class="reserved">this</span>.element.dom.select();
}catch(e){}
}
<span class="reserved">this</span>.validate(<span class="reserved">this</span>.element.dom.value);
};
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.getValue = <span class="reserved">function</span>(){
<span class="reserved">if</span>(!<span class="reserved">this</span>.validate()){
<span class="reserved">return</span> <span class="reserved">this</span>.originalValue;
}<span class="reserved">else</span>{
var value = <span class="reserved">this</span>.element.dom.value;
<span class="reserved">if</span>(value.length &lt; 1){
<span class="reserved">return</span> value;
} <span class="reserved">else</span>{
<span class="reserved">return</span> <span class="reserved">this</span>.fixPrecision(<span class="reserved">this</span>.parseValue(value));
}
}
};
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.parseValue = <span class="reserved">function</span>(value){
<span class="reserved">return</span> parseFloat(new String(value).replace(<span class="reserved">this</span>.decimalSeparator, <span class="literal">'.'</span>));
};
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.fixPrecision = <span class="reserved">function</span>(value){
<span class="reserved">if</span>(!<span class="reserved">this</span>.allowDecimals || <span class="reserved">this</span>.decimalPrecision == -1 || isNaN(value) || value == 0 || !value){
<span class="reserved">return</span> value;
}
<span class="comment">// this should work but doesn't due to precision error in JS</span>
<span class="comment">// var scale = Math.pow(10, this.decimalPrecision);</span>
<span class="comment">// var fixed = this.decimalPrecisionFcn(value * scale);</span>
<span class="comment">// return fixed / scale;</span>
<span class="comment">//</span>
<span class="comment">// so here's our workaround:</span>
var scale = Math.pow(10, <span class="reserved">this</span>.decimalPrecision+1);
var fixed = <span class="reserved">this</span>.decimalPrecisionFcn(value * scale);
fixed = <span class="reserved">this</span>.decimalPrecisionFcn(fixed/10);
<span class="reserved">return</span> fixed / (scale/10);
};
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.allowBlank = true;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.allowDecimals = true;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.decimalSeparator = <span class="literal">'.'</span>;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.decimalPrecision = 2;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.decimalPrecisionFcn = Math.floor;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.allowNegative = true;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.selectOnFocus = true;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.minValue = Number.NEGATIVE_INFINITY;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.maxValue = Number.MAX_VALUE;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.minText = <span class="literal">'The minimum value for this field is %0'</span>;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.maxText = <span class="literal">'The maximum value for this field is %0'</span>;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.blankText = <span class="literal">'This field cannot be blank'</span>;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.nanText = <span class="literal">'%0 is not a valid number'</span>;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.validationDelay = 100;
YAHOO.ext.grid.NumberEditor.<span class="reserved">prototype</span>.validator = <span class="reserved">function</span>(){<span class="reserved">return</span> true;};</pre>
<hr>
<hr>
<font size="-1">
</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Sat Oct 14 06:07:10 2006</div>
</body>
</html>