Advertisement:

Author Topic: [TUTORIAL] Allow Numbers Only In Price Field  (Read 4753 times)

zoopla

  • Guest
[TUTORIAL] Allow Numbers Only In Price Field
« on: February 07, 2014, 08:07:04 am »
Just a small Mod that you might find useful...

As you see in price field users are able to write anything  (dfds7678*&*...) - Not just numbers.

Follow these steps to  allow users to enter only numerical values (1234566)

In this tutorial I'm explaining how to do that in Bender theme but it should be similar in other themes.

Open item.php file  from your theme folder

Find this code

Code: [Select]
<?php if( osc_price_enabled_at_items() ) { ?>
                        <div class="control-group">
                            <label class="control-label" for="price"><?php _e('Price''bender'); ?></label>
                            <div class="controls">
                                <?php ItemForm::price_input_text(); ?>
                                <?php ItemForm::currency_select(); ?>
                            </div>
                        </div>
                        <?php ?>


And replace it with this

Code: [Select]
    <?php if( osc_price_enabled_at_items() ) { ?>
                        <div class="control-group">
                            <label class="control-label" for="price"><?php _e('Price''bender'); ?>(Numbers Only)</label>
                            <div class="controls" id="nbr">
                                <?php ItemForm::price_input_text(); ?>
                                <?php ItemForm::currency_select(); ?>
                            </div>
                        </div>
<script type="text/javascript">
$('#nbr').on('keypress', function(ev) {
    var keyCode = window.event ? ev.keyCode : ev.which;
    //codes for 0-9
    if (keyCode < 48 || keyCode > 57) {
        //codes for backspace, delete, enter
        if (keyCode != 0 && keyCode != 8 && keyCode != 13 && !ev.ctrlKey) {
            ev.preventDefault();
        }
    }
});

</script>
<?php ?>


Here you go! :)  Now users can only input numbers in the price field.

Regards, ibthemes.com

« Last Edit: February 07, 2014, 08:09:09 am by Ibthemes.com »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: [TUTORIAL] Allow Numbers Only In Price Field
« Reply #1 on: February 07, 2014, 03:32:12 pm »
Many thanks Ibthemes, this is very usefull mod ;)

Regards
dev101

gnoe

  • Full Member
  • ***
  • Posts: 237
Re: [TUTORIAL] Allow Numbers Only In Price Field
« Reply #2 on: February 10, 2014, 09:02:48 pm »
Great thanks Ibthemes :)

zoopla

  • Guest
Re: [TUTORIAL] Allow Numbers Only In Price Field
« Reply #3 on: February 11, 2014, 05:35:54 pm »
Great thanks Ibthemes :)
Many thanks Ibthemes, this is very usefull mod ;)

Regards
dev101

Glad you found it useful guys...  Hopefully more tips and tutorials will follow soon...

Regards,
Ibthemes.com

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: [TUTORIAL] Allow Numbers Only In Price Field
« Reply #4 on: February 11, 2014, 06:38:49 pm »
thank you!! looking forward to more tips :-)

zoopla

  • Guest
Re: [TUTORIAL] Allow Numbers Only In Price Field
« Reply #5 on: February 16, 2014, 04:16:06 pm »
thank you!! looking forward to more tips :-)
Thanks - Im preparing  tons of video tutorials that will be added in here and on my site ibthemes.com Soon :)

boboclock

  • Newbie
  • *
  • Posts: 23
Re: [TUTORIAL] Allow Numbers Only In Price Field
« Reply #6 on: April 28, 2014, 06:51:40 pm »
I like this very much, however, I am having trouble adding periods to the list of allowed characters. I have tried editing to no avail:
Code: [Select]
if (keyCode != 0 && keyCode != 8 && keyCode != 13 && keyCode != 190 && !ev.ctrlKey)

elod

  • Jr. Member
  • **
  • Posts: 51
Re: [TUTORIAL] Allow Numbers Only In Price Field
« Reply #7 on: June 06, 2014, 11:35:11 pm »
And if i use modern theme.... ?? oly thin in the item.php that is relativ the price is this

<h1><?php if( osc_price_enabled_at_items() && osc_item_category_price_enabled() ) { ?><span class="price"><?php echo osc_item_formated_price(); ?>&nbsp;&nbsp;<strong><?php osc_has_item_meta(); echo osc_item_meta_value(1); ?></strong></strong></span> <?php } ?><strong><?php echo osc_item_title() . ' ' . osc_item_city(); ?></strong></h1>
                    <?php if(osc_is_web_user_logged_in() && osc_logged_user_id()==osc_item_user_id()) { ?>

loythegreat

  • Newbie
  • *
  • Posts: 11
Re: [TUTORIAL] Allow Numbers Only In Price Field
« Reply #8 on: February 08, 2016, 09:47:05 am »
I like this very much, however, I am having trouble adding periods to the list of allowed characters. I have tried editing to no avail:
Code: [Select]
if (keyCode != 0 && keyCode != 8 && keyCode != 13 && keyCode != 190 && !ev.ctrlKey)
I would like to know the solution to this too. Anyone?