Giter VIP home page Giter VIP logo

yii2-number's Introduction

Krajee Logo
yii2-number
Donate

Latest Stable Version Latest Unstable Version License Total Downloads Monthly Downloads Daily Downloads

Note

This extension replaces the yii2-money extension since Jan 2018. The yii2-money extension will not be enhanced further or supported.

A number control input for Yii2 Framework that uses the jQuery input mask plugin (available also via yii/widgets/MaskedInputAsset) to render number input masks. This extension is similar to the DateControl extension for dates, and allows one to control the display and save formats for numbers. The extension thus allows one to setup a number format display mask, use currency prefixes if needed, and modify the decimals and thousand separators. It lastly allow the display fields to be auto calculated as numbers when stored into the database.

Refer detailed documentation and demos.

Release Updates

Refer the CHANGE LOG for updates and changes to various releases.

Install

Either run

$ php composer.phar require kartik-v/yii2-number "@dev"

or add

"kartik-v/yii2-number": "@dev"

to the require section of your composer.json file.

Usage

use kartik\number\NumberControl;

// Normal decimal
echo NumberControl::widget([
    'name' => 'normal-decimal',
    'value' => 43829.39,
]);

// Integer only
echo NumberControl::widget([
    'name' => 'integer-only',
    'value' => 32892,
    'maskedInputOptions' => ['digits' => 0],
]);

// Currency style with prefix and suffix
echo NumberControl::widget([
    'name' => 'currency-num',
    'value' => 2018032.22,
    'maskedInputOptions' => ['prefix' => '$ ', 'suffix' => ' c'],
]);

// Usage with model 
$model->currency = 1298132.23;
echo NumberControl::widget([
    'model' => $model,
    'attribute' => 'currency',
    'maskedInputOptions' => ['prefix' => '$ ', 'suffix' => ' c'],
]);

License

yii2-number is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

yii2-number's People

Contributors

kartik-v avatar kevocde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

yii2-number's Issues

Javascript console error, and non functioning widget

After a recent composer update, I'm getting the following error at the console...

Uncaught SyntaxError: expected expression, got '<'[jquery.inputmask.bundle.js:1:3]
Uncaught TypeError: $elDisp.inputmask is not a function

Everything working fine before the update..

Quite a few packages updated..

  • Upgrading yiisoft/yii2-composer (dev-master 30d9c84 => dev-master 2cd6eee): Extracting archive
    • Upgrading bower-asset/punycode (v1.3.2 => v2.2.3): Extracting archive
    • Upgrading bower-asset/inputmask (3.3.11 => 5.0.9-beta.32): Extracting archive
    • Upgrading yiisoft/yii2 (dev-master ceb3e20 => dev-master f4f97f0): Extracting archive
    • Upgrading tinymce/tinymce (6.7.0 => dev-master 02e194e): Extracting archive
    • Upgrading phpunit/php-code-coverage (9.2.x-dev 55a161b => 9.2.x-dev a296fae): Extracting archive
    • Upgrading phpunit/phpunit (9.6.x-dev bf8634b => 9.6.x-dev b1b544b): Extracting archive
    • Upgrading psr/event-dispatcher (dev-master e275e2d => dev-master 977ffcf): Extracting archive
    • Upgrading psr/http-factory (dev-master 6d70f40 => dev-master 7037f4b): Extracting archive
    • Upgrading guzzlehttp/psr7 (2.6.x-dev 2ce93c4 => 2.6.x-dev 38ef514): Extracting archive
    • Upgrading psr/http-client (dev-master 0955afe => dev-master bb5906e): Extracting archive
    • Upgrading guzzlehttp/guzzle (7.8.x-dev 56a99b5 => 7.9.x-dev d95d9ab): Extracting archive
    • Upgrading psr/container (dev-master 90db7b9 => dev-master 7079847): Extracting archive
    • Upgrading illuminate/collections (10.x-dev f494398 => 10.x-dev 133f599): Extracting archive
    • Upgrading kartik-v/bootstrap-fileinput (dev-master 8f4a40f => dev-master 0731fae): Extracting archive
    • Upgrading components/flag-icon-css (dev-main 59ac20a => dev-main 6784329): Extracting archive
    • Upgrading setasign/fpdi (v2.4.1 => v2.5.0): Extracting archive
    • Upgrading mpdf/psr-http-message-shim (2.0.0 => v2.0.1): Extracting archive
    • Upgrading symfony/mime (6.4.x-dev 4f1791b => 6.4.x-dev fae6d88): Extracting archive
    • Upgrading fakerphp/faker (v1.23.0 => 1.23.x-dev 8d32135): Extracting archive
    • Upgrading symfony/process (6.4.x-dev 2adbb78 => 6.4.x-dev 7a98cdf): Extracting archive
    • Upgrading yiisoft/yii2-queue (dev-master 726a4fd => dev-master 17fcf6a): Extracting archive
    • Upgrading symfony/mailer (6.4.x-dev 70b7234 => 6.4.x-dev c445b16): Extracting archive
    • Upgrading twig/twig (3.x-dev fd8f61b => 3.x-dev 3ae6fb8): Extracting archive

Any suggestions as to what I might try to find the issue ?
Thanks.

Confic with Yii 2 File Kit extendsion

Prerequisites

i try to setup so Yii 2 File Kit upload not working

Steps to reproduce the issue

  1. Add Widget
  2. Run update
  3. Not work

Expected behavior and actual behavior

When I follow those steps, I see...
image

I was expecting...

Environment

Browsers

  • [ x] Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • [ x] Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version:
  • yii2-number version:
  • yii2-file-kit

Set default save input type to text for correct form reset

Default the save input rendered as text input type. This will allow values to be reset correctly on form reset.

Set the default display of the save container to display:none within saveInputContainer to not display the save input by default.

Two inputs showing with new Yii2 Version

Steps to reproduce the issue

  1. install most recent Yii2 version
  2. install most recent Number Control
  3. The form shows the two boxes, the one linked to the model and the one used for display

Expected behavior and actual behavior

To see only one box

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox

Operating System

  • Windows
  • Mac OS X

Libraries

  • jQuery version:
  • yii2-number version: 1.0.5
  • yii2: 2.0.38

Isolating the problem

  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-number without other plugins.

Code:

<p class="div-line m-r-10 m-tb-0">My minimum hourly price is </p>
<?= $form->field($user, 'price_min', ['options' => ['class' => 'w-150p m-r-10 form-group']])->widget(NumberControl::classname(), [
    'maskedInputOptions' => [
        'prefix' => '',
        'suffix' => ' USD',
        'allowMinus' => false
    ],
])->label(false); ?>
<p class="div-line m-r-10 m-tb-0">and maximum hourly price is </p>
<?= $form->field($user, 'price_max')->widget(NumberControl::classname(), [
    'maskedInputOptions' => [
        'prefix' => '',
        'suffix' => ' USD',
        'allowMinus' => false
    ],
])->label(false); ?>

Rendered behavior:

Screenshot 2020-11-11 at 1 04 07 PM

Bug using widget into Form Builder

Hi, the form with kartik\number\NumberControl doesn't work anymore.

The form field configuration is

'INPUT_NUM_1'       => [
                'attribute'   => 'INPUT_NUM_1',
                'type'        => constant('\kartik\builder\Form::INPUT_WIDGET'),
                'widgetClass' => 'kartik\number\NumberControl',
                'options'     => [
                    'maskedInputOptions' => [
                        'allowMinus' => false,
                        'rightAlign' => false,
                        'digits'     => 0,
                    ],
                ],
                'label'       => $this->getAttributeLabel('INPUT_NUM_1'),
            ],

The input is not inserted into the right attribute, so when I load() the model the value isn't passed
immagine

jQuery form.serialize() error using NumberControl

jQuery error:

TypeError: val.replace is not a function

PHP Code:

$form = ActiveForm::begin([
    'id' => 'app-form',
    'formConfig' => ['labelSpan' => 3, 'deviceSize' => ActiveForm::SIZE_SMALL]
]);
$dispOptions = ['class' => 'form-control kv-monospace'];
echo $form->field($model, 'total_expenses')->widget(NumberControl::classname(), [
    'maskedInputOptions' => [
        'suffix' => ' MYR',
        'allowMinus' => false
    ],
    'displayOptions' => $dispOptions,
]);
ActiveForm::end();

JavaScript code:

var form = $("#app-form");
var serialized = form.serialize(); //serialize test

Click on label does not focus on input field (number)

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-number.
  • This is not an usage question. I confirm having gone through and read the documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

  1. Include a number field in the form like this:
<?= $form->field($ergo, 'myfield')->widget(
    NumberControl::class,
    [
        'maskedInputOptions' => [
            'prefix' => '€ ',
            'groupSeparator' => '.',
            'radixPoint' => ',',
        ],
        'displayOptions' => ['class' => 'form-control'],
    ]) ?>
  1. Yii renders the label and input field.

Expected behavior and actual behavior

When I follow those steps and I click on the label, the browser does not focus inside the input field.

I was expecting the mouse cursor to focus inside the number field.

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 3.4.1
  • yii2-number version: 2.0.31

Isolating the problem

  • This bug happens on the docs and demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-number without other plugins.

unmaskAsNumber not working

Since version 1.0.2 properties unmaskAsNumber and autoUnmask is not working at all. If you put them as false, it's still making a conversion for standard float mask after blur, until version 1.0.1 working as properly.

Config Ex.:
'maskedInputOptions' => [
'groupSeparator' => '.',
'radixPoint' => ',',
'autoUnmask' => false,
'unmaskAsNumber' => false,
],

Input:
image

Expect behavior:
image

Obtained behavior:
image

Problem with 3 digits

i think i have found a bug in yii2-number.

I'm working with 3 digits but there is a problem with the maskedInput when it's 3 digits, when i put for example 144.427 as a default value, groupSeparator =>'.' and 'radixPoint' => ',' the number that appear in input it's "144.427" and not "144,427". And if i put "144.42" the number that appear in input it's "144,42" that is correct.

My code:
echo NumberControl::widget([
'name' => 'test',
'value' => 144.427,
'maskedInputOptions' => [
'suffix' => ' %',
'groupSeparator' => '.',
'radixPoint' => ',',
'digits' => 3,
],
]);
?>

Unable to enter negative values ​​with suffix

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-number.
  • This is not an usage question. I confirm having gone through and read the documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

  1. Create new NumberControl input with a suffix. Example:
    'maskedInput' => ['suffix' => ' €']
  2. Use js to set a negative number value. Example:
    $('#myId-disp').inputmask("setvalue", -2);

Expected behavior and actual behavior

When I follow those steps, I see the number '0' appear in field and not the number chosen. If I try with a positive number everything works correctly. If I try with a prefix everything works correctly

Environment

  • Apache server
  • PHP 7.2.13

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 3.4.1
  • yii2-number version: last dev-master

Isolating the problem

  • This bug happens on the docs and demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-number without other plugins.

Numbers with comma as decimal will save the number as string with the comma

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-number.
  • This is not an usage question. I confirm having gone through and read the documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

The best way to reproduce is searching the NumberControl demo for "German Amount" and changing the input value, this will give the same result as in my code.
Still, here is how to get there by coding:

  1. Create a NumberControl widget inside a form with 'radixPoint' => ','
echo NumberControl::widget([
    'name' => 'amount_german',
    'value' => 78232.01,
    'maskedInputOptions' => [
        'groupSeparator' => '.',
        'radixPoint' => ','
    ],
]);
  1. Change the default value and submit the form.
  2. Check the submitted data.

Expected behavior and actual behavior

When I follow those steps, I see the number as a string with the comma as the decimal separator, i.e.: "1234,01".

I was expecting to get the number as a number, having decimals separated by a dot, i.e.: 1234.01.
Since the initial value passed to the widget is a number with dot as decimal separator, I expect to receive a number with a dot as decimal separator from the widget. Thus, keeping the data integrity.

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 3.2.1
  • yii2-number version: 1.0.1

Isolating the problem

  • This bug happens on the docs and demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-number without other plugins.

Need to use `onkeypress`, `onkeydown`, or `onkeyup` to get value

Steps to reproduce the issue

  1. install most recent Yii2 version
  2. install most recent Number Control

Expected behavior and actual behavior

expected behavior : I can use onkeypress, onkeydown, or onkeyup to get value..

actual behavior : I can only use onchange to get value..

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox

Operating System

  • Windows
  • Linux

Libraries

  • jQuery version : 3.5.1
  • yii2-number version : 1.0.5
  • yii2 version : 2.0.40

Isolating the problem

  • This bug happens on the docs and demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-number without other plugins.

this is my code :

<?= $form->field($target, "[$index]anggaran")->widget(NumberControl::classname(), [
    'maskedInputOptions' => [
        'prefix' => 'Rp. ',
        'groupSeparator' => '.',
        'radixPoint' => ',',
        'allowMinus' => false,
        'digits' => 1000,
    ],
    'options' => ['onkeypress' => 'kalkulasiAnggaran()'],
    'displayOptions' => ['class' => 'form-control kv-monospace'],
])->label(false) ?>

and this is my Javascript function :

function kalkulasiAnggaran()
{
    var total_anggaran = 0;
    total_anggaran = parseFloat($("#anggaran").val());

    console.log(total_anggaran.toFixed(2));
}

I need to use onkeypress, onkeydown, or onkeyup, but this extension only allowed onchange..

Value not valid in gridview

In gridview, when I type a value and press [Enter], the value is not sent to the server correctly using decimal as a comma. If I press [Tab] it works normally.

[ 'attribute' => 'valor', 'format' => 'decimal', 'filterType' => '\kartik\\number\\NumberControl', ],

giving id to the element

field($model, 'service_charge')->textInput(['id' => 'ServcieCharge']) ?>
<!-- <?= $form->field($model, 'service_charge')->widget(NumberControl::classname(), [
    
'maskedInputOptions' => [
    'prefix' => ' ₹  ',
    'suffix' => ' c',
    'allowMinus' => false
    ],
    //'options' => $saveOptions,
    //'displayOptions' => $dispOptions,
    //'saveInputContainer' => $saveCont
    'id' => 'ServcieCharge'
]); ?> -->

'kartik\number\Yii'

Error: Class 'kartik\number\Yii' not found.

You could use:
$formatter = \Yii::$app->formatter;
instead of this:
$formatter = Yii::$app->formatter;

Pressing the "enter" key does not change the input value

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-number.
  • This is not an usage question. I confirm having gone through and read the documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

  1. Define a data table with GridView.
  2. Define a column that uses this widget.
  3. Place a test value and press tab.
  4. Now press go to the field again, change the value and press the enter key.

Expected behavior and actual behavior

  • When I follow those steps, I see...
    The search is performed but it remains with the previous value to press the tab key and not the new value.
  • I was expecting...
    The search is performed with the indicated value when pressing the enter key

Environment

  • Apache server
  • PHP 7.1

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 3.2.1
  • yii2-number version: 1.0.4

Isolating the problem

  • This bug happens on the docs and demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-number without other plugins.

It is not possible to set the value via javascript

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-number.
  • This is not an usage question. I confirm having gone through and read the documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

  1. Use the Number widget
<?= $form->field($item, 'price', ['options' => ['class' => 'col-md-2']])
    ->widget(NumberControl::class, [
        'maskedInputOptions' => [
            'groupSeparator' => '.',
            'radixPoint' => ','
        ],
    ]);?>
  1. Try entering the value via Javascript
var input = document.getElementById('".Html::getInputId($item, 'price')."');
input.inputmask.setValue('4050');
  1. Error
Cannot read property 'setValue' of undefined

Expected behavior and actual behavior

When I follow those steps, I see...

I was expecting...

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version:
  • yii2-number version:

Isolating the problem

  • This bug happens on the docs and demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-number without other plugins.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.