On May 2, 2012, at 6:35 AM, Edward Nygma wrote:
>
>
> Hello welcome to my application to see the problem please visit the
> link above, please click 'login' where the user and pass are already
> entered. You will be taken to the dashboard, then click the blue link
> 'Nick Fish' and on the following page 'Edit invoice'. You should see a
> large form for invoicing, this is the Prototype functionality that
> needs to be viewed.
>
> Please enter a number into the 'qty' or 'price' fields of the table
> and notice a returned numeric total, but if a letter or something that
> isn't a number is typed into the input boxes, NaN is returned in
> multiple boxes which isn't every user friendly.
>
> Are there any simple revisions I can make to my prototype code below
> that prompt/ensure some validation of numbers entered into 'qty' and
> 'price' or replace the NaN that is returned with 'error enter a
> number'?
Unless 0 is a valid entry, maybe you could add parseInt or parseFloat to the
party?
var amount = parseFloat($F('your_field'));
if(! amount > 0){
//your error here
}else{
//do something here
}
Walter
>
> var Invoice = Class.create({
>
> line_item_number: 1,
>
> initialize: function(html, item) {
> this.line_item_html = html
> this.line_item_number = item
> this.validate();
> },
>
> is_valid: function() {
> return ($F('InvoiceClientId') != '' && this.total() > 0)
> },
>
> validate: function() {
>
>
> if(this.is_valid())
> {
> Field.enable('save');
> $('note').style.display = 'none'
> return true
> }
> else
> {
> Field.disable('save')
> $('note').style.display = ''
> return false
> }
>
> },
>
> indexed_line_item_html: function() {
> return this.line_item_html.replace(/INDEX_ID/g,
> this.line_item_number)
> },
>
> add_line_item: function() {
> $('items').insert(this.indexed_line_item_html())
> $('Item'+String(this.line_item_number)+'Quantity').focus()
> this.line_item_number++
>
> },
>
> remove_line_item: function(index) {
> Element.remove(index)
> this.refresh()
> },
>
>
>
> to_money: function(amount) {
> return Number(amount).toFixed(2)
> },
>
>
> sub_total: function() {
> var In = this
> return $$('.item').inject(0, function(sum, row) {
> var quantity = Number($F('Item' + row.id + 'Quantity'))
> var price = Number($F('Item' + row.id + 'Price'))
> var line_total = quantity * price
> $('Item' + row.id + 'Quantity').value = In.to_money(quantity)
> $('Item' + row.id + 'Price').value = In.to_money(price)
> $('Item' + row.id + 'Total').update('£' +
> In.to_money(line_total))
> return sum + line_total
> })
> },
>
> tax: function() {
> var tax_rate = Number($F('InvoiceTaxRate')) // passes in an item
> var taxable_amount = this.sub_total()
> tax_total = Math.round((tax_rate * 0.01 * taxable_amount) *
> 1000) / 1000
> return Math.round(tax_total * 100) / 100
> },
>
> total: function() {
> return this.sub_total() + this.tax()
> },
>
> refresh: function() {
> $('subtotal').update('£' + this.to_money(this.sub_total()))
> $('total').update('£' + this.to_money(this.total()))
> $('tax').update('£' + this.to_money(this.tax()))
> this.validate();
> }
>
>
> });
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prototype & script.aculo.us" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.