Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-2835

An Amountbox implementation like Decimalbox

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: 7.0.5
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I currently use a Decimalbox to get an amount from client, which is very useful for me since no letters are accepted.

      If the entry from client (Decimalbox) contains sepcial characters like ",,..--.,." an error message appears "You must specify a number, rather than x." on the input field. This message comes from Decimalbox.js @ coerceFromString_ method:

      zul.inp.Decimalbox = zk.$extends(zul.inp.NumberInputWidget, {
      	$define: { 
      		
      		
      		scale: null
      	},
      	coerceFromString_: function (value) {
      		if (!value) return null;
      
      		var info = zk.fmt.Number.unformat(this._format, value, false, this._localizedSymbols),
      			val = new zk.BigDecimal(info.raw),
      			sval = val.$toString();
      		if (info.raw != sval && info.raw != '-'+sval) 
      			return {error: zk.fmt.Text.format(msgzul.NUMBER_REQUIRED, value)};
      			
      		if(this._rounding == 7 && (this._errmsg ||
      		zk.fmt.Number.isRoundingRequired(value, this.getFormat(), this._localizedSymbols)))
      			return {server:true};
      			
      		if (info.divscale) val.setPrecision(val.getPrecision() + info.divscale);
      		if (this._scale > 0) 
      			val = zk.fmt.Number.setScale(val, this._scale, this._rounding);
      		return val;
      	},
      	coerceToString_: function(value) {
      		var fmt = this._format;
      		return value != null ? typeof value == 'string' ? value : 
      			fmt ? zk.fmt.Number.format(fmt, value.$toString(), this._rounding, this._localizedSymbols)
      			: value.$toLocaleString() : '';
      	},
      	marshall_: function(val) {
      		return val ? val.$toString() : val;
      	},
      	unmarshall_: function(val) {
      		return val ? new zk.BigDecimal(val) : val; 
      	},
      	getAllowedKeys_: function () {
      		var symbols = this._localizedSymbols;
      		return this.$supers('getAllowedKeys_', arguments)
      			+ (symbols ? symbols: zk).DECIMAL; 
      	}
      });
      

      (See org\zkoss\zk\zul\7.0.5\zul-7.0.5\web\js\zul\inp\Decimalbox.src.js ; Line: 15 + 16)

      if (info.raw != sval && info.raw != '-'+sval) 
          return {error: zk.fmt.Text.format(msgzul.NUMBER_REQUIRED, value)};
      
      

      Reason:
      This message is wrong for an "Amountbox".
      Instead of:
      #-=NUMBER_REQUIRED
      2041=You must specify a number, rather than

      {0}.

      Better:
      2041=You must specify a amount, rather than {0}

      .

      If the client-side validation is removed, i can validate that in my AmountConstraint class.

      I would appreciate if there is an Amountbox which doesn't allow characters (behavior of Decimalbox) such as the Decimalbox, except the client-side validation on javascript side.

      Best regards,

      Salbader

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            salbader salbader
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: