Is there a way to create a single line text field for entering the coupon code? This would be especially useful when only one code is allowed. Also the text under the input box could change depending if you could have more than one coupon code.

Thanks,

Sam

CommentFileSizeAuthor
#23 single_line.png7.43 KBbellagio

Comments

ryangroe’s picture

I believe this could be done with javascript. I can help you with that over the weekend.

sam_RiteTimeDirect’s picture

great

TwistedLincoln’s picture

I too am interested in such a feature!

ryangroe’s picture

Here is the javascript:

$(document).ready(function()
{
$(".discount-codes-wrapper").each(function()
{
var wrapper = $(this);
wrapper.find("textarea").attr("rows", 1).css("height", "1em");
wrapper.find(".grippie").hide();
});
});

The way I have my site setup is to add a template.php file to my theme (must be phptemplate theme) with the contents:
<?php
drupal_add_js(drupal_get_path("theme", $GLOBALS["theme_key"]) . "/main.js", "module");

Then add a main.js to my theme with the javascript contents above.

sam_RiteTimeDirect’s picture

Thanks a lot. I will take a crack at it.

Sam

gooddesignusa’s picture

thanks came in useful. just added this to my page.tpl.php file

<?php if($_GET['q'] == "cart/checkout"){ ?>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(function(){
	$(".discount-codes-wrapper").each(function()
	{
		var wrapper = $(this);
		wrapper.find("textarea").attr("rows", 1).css("height", "1em");
		wrapper.find(".grippie").hide();
	});	
	$("#uc_discounts-pane .description").text("Enter discount codes in the box below.");	
});
//--><!]]>
</script>
<? } ?>
ryangroe’s picture

Sam and TwistedLincoln, can you confirm this works for you?

gooddesignusa’s picture

The real way would be to have an area in the module for how big the text-area should be. But that really isn't a big deal since this jquery can easily do it. Maybe something to add at the bottom of the to do list.

ryangroe’s picture

Ya, my solution is crude. I will add a global module config section at some point and allow for size changes there.

TwistedLincoln’s picture

It does work for me, but doesn't seem to expand the box as needed if you need to add more than one coupon.

Maybe it would be better to have a simple input box (one line, one item), and add the ability for the module to apply coupons separately one at a time. Then have a "remove" link next to the description of each applied code so the user could remove coupons individually if desired.

ryangroe’s picture

To make the box user-resizable remove " wrapper.find(".grippie").hide();".

I considered the multiple box idea before but I thought it too difficult for the users of my site. We could revisit it sometime in the future.

ferrangil’s picture

Subscribing!
A simple value on the settings page would be great for selecting 1 (ie single line) or 5 (ie text area).

RachelNY’s picture

Subscribing ... would also like to see this on a settings page ...

chrisjohnson’s picture

cheers using the javascript i got the coupon bar to sick

agilpwc’s picture

what would be the javascript code to hide the text area? I don't use codes on my site, so wanted to get rid of text box in the pane.

Zalatar’s picture

#uc_discounts-pane { display: none; }

Put this in you sites theme style.css file. This will hide the discounts pane on the checkout page.

Z

ezra-g’s picture

You could also achieve this server-side with a form alter to change the field from a textarea to a textfield.

tanjerine’s picture

i just had to implement this one, so i'm posting how i did it (please feel free to correct me if there's a better way of doing this):

first did an alter form (custom module using hook_form_alter):

	case 'uc_cart_checkout_form' :
        // alter form for discount codes
         $form['panes']['uc_discounts']['uc-discounts-codes'] = array(
          '#type' => 'textfield',
          '#maxlength' => 25,
         );
        break;

then altered the uc_discounts.js file (~line 38) since this checks the value of the discount and applies it:

	//parameterMap["uc-discounts-codes"] = $("textarea[id*=uc-discounts-codes]", context).val();
	parameterMap["uc-discounts-codes"] = $("input#edit-panes-uc-discounts-uc-discounts-codes", context).val();

~S

bellagio’s picture

@tanjerine
Could you kindly explain where to put the first code? :)

tanjerine’s picture

hi bellagio,

I created a custom module with that code:

note: my module's name is alter module page and the file that contains this is alter_modules_page.module

function alter_modules_page_form_alter(&$form, $form_state, $form_id) {
 switch ($form_id) {
        case 'uc_cart_checkout_form' :
          // alter form for discount codes

          $form['panes']['uc_discounts']['uc-discounts-codes'] = array(
              '#type' => 'textfield',
              '#default_value' => $codes_string,
              '#maxlength' => 25,
        );
        break;
 } 

Hope this helps,
~S

bellagio’s picture

My knowledge is too short to implement your solution. Sounds like I need to make a module to make this function work. :(
Figuring out how module works is hard enough for me.
I am scratching my head.. but thank you for replying.

jrust’s picture

Status: Active » Fixed

Comment #20 is definitely the best way to go, no javascript needed. See the example form module if you need help creating a simple module with the code from #20.

bellagio’s picture

StatusFileSize
new7.43 KB

now i have a single line coupon code. Thank you!

This is how i made custom module (for newbies like me).
Make new folder named 'alter_modules_page' under sites/all/modules
copy code from #20 and save it as alter_modules_page.module.

<?php
function alter_modules_page_form_alter(&$form, $form_state, $form_id) { 
switch ($form_id) {        
case 'uc_cart_checkout_form' :          
// alter form for discount codes          
$form['panes']['uc_discounts']['uc-discounts-codes'] = array(              
'#type' => 'textfield',              
'#default_value' => $codes_string,              
'#maxlength' => 25,        
);        
break; 
} 
}

'alter_modules_page' module is not listed under admin/sitebuilding/module because there is no alter_modules_page.info file in the module folder.

create simple .info file like

name = alter modules page
description = alter modules page.
core = 6.x

Then save this as alter_modules_page.info in the alter_modules_page folder

Your new module will be listed under 'Other' in admin/sitebuilding/module. Enable it then you will see single line code(screenshot attached) during the checkout page.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

panigrc’s picture

Thank you very much for that.

squarecandy’s picture

#18 works great for me - I had figured out changing the textarea to textfield on the form, but the js part was confounding me. Thanks tanjerine!