2014-09-09 4 views
0

숫자 값을 입력하고이 코드를 사용하고 있습니다 :JqueryUI 회 전자의 NumberFormat 통화 나는 JQuery와 통화 입력이

$('input[name="precio"]').spinner({ 
    min:0, 
    numberFormat: 'C' 
}); 

는 $와 숫자 또는에 따라 € 기호와 숫자를 같이 입력은 완벽하게 작동 세계화.

문제는 양식을 제출할 때 "5,00 €"과 같은 텍스트가 나오고 숫자 값이 5.00 또는 500이되고 싶습니다.

이렇게 할 방법이 있습니까? 미리 감사드립니다.

답변

0

좋아 I finnaly는 내가 원하는 방식으로이 작업을 수행했습니다. 난 그냥 JQueryUI에서 회를 확장하는 플러그인라는 이름의 currencyspinner을 만들었습니다, 여기에 코드입니다 : 나는 같은 이름의 숨겨진 입력을 만들고 그것을 아리아 - valuenow마다의 값을 제공

$.widget("ui.currencyspinner", $.ui.spinner, { 
    options: { 
     numberFormat: 'C', // Currency Format 
     min:0, 
     step:0.10 
    }, 
    _create: function(){ 
     this.hidden = $('<input type="hidden" value="'+this.element.val()+'" name="'+this.element.attr('name')+'">'); // Create a hidden input with the same name and value 
     this.element.removeAttr('name'); // remove the name of the original element 
     this.element.before(this.hidden); // insert the hidden element before the original element 
     return this._super(); 
    }, 

    _refresh: function() { 
     this.hidden.val(this._parse(this.element.val())); // put the aria-valuenow on the original element 
     return this._super(); 
    }, 

    _destroy: function(){ 
     this.element.attr('name',this.hidden.attr('name')); // put back the name on the original value 
     this.hidden.remove();        // remove the hidden element 
     return this._super(); 
    } 
}); 

스피너 새로 고침 .

currencyspinner를 생성 한 후 currencyspinner에 액세스하려는 경우 $('input[name="nameoftheelement"]').currencyspinner(...);을 사용할 수 없으므로이 입력란은 숨겨진 입력이며 회 전자 자체는 사용할 수 없으므로주의하십시오.

나는 그것이 누군가를 돕기를 희망한다!

1

는 (코멘트에서 귀하의 질문에 대답하기 (포맷없이) 현재의 숫자 값을 가져옵니다 해당 입력에 대한 '아리아 - valuenow'

http://jsfiddle.net/ma8zd7mg/1/

$("#spinner").spinner({ 
    min: 0, 
    numberFormat: "C" 
}); 

$("#test").click(function(){ 
    alert($("#spinner").attr('aria-valuenow')); 
}); 

편집라는 속성입니다) PHP로 제출 한 후 값을 얻으려면 다음을 할 수 있습니다. 1. 스피너의 숫자 값을 가져 오는 자리 표시 자 입력을 만들고 값이 제출됩니다. 2. PHP를 사용하여 추가 형식 문자를 제거합니다 $,. 그리고 여분 제로)

는이 같은 뭔가 첫 번째 방법을 권장합니다

$("#submit-btn").click(function(e){ 
    //prevent the form submission 
    e.preventDefault(); 

    //add a placeholder input with the value of the spinner 
    $("#my-from").append('<input/>', { 
     'type': 'hidden', 
     'name': 'spinner-value', 
     'value': $("#spinner").attr('aria-valuenow') 
    }); 

    //now submit the form 
    $("#my-form").submit(); 
}); 

그런 다음 PHP에서 당신은 그냥 얻을 수있는 '스피너 값'입력

<?php 
$spinner = $_REQUEST['spinner-value']; 
.... 
.... 
?> 
+0

감사합니다. 하지만 제출 후 PHP에서 값을 사용하려면, 제출하기 전에 ariavalue 입력을 변환하는 데 필요한 또는 numberFormat C (플러그인 또는 뭔가)와 함께 각 회 전자에 대해 자동으로 그것을 할 방법이 있습니까? –

+0

답변을 업데이트했습니다. 도움이된다면 답을 표시해주세요. –

+0

고마워, 내가 그런 것을 할 것 같아. 초기 개체와 동일한 이름과 ID를 가진 숨겨진 입력에 아리아 값을 저장할 수있는 스피너의 확장이 존재하고 다른 시각적 입력에서 사용자에게 서식있는 숫자를 보여주기를 바랬습니다. datepicker altfield 및 altformat와 유사합니다. –