From 67a2912537d4f7af5c69d4ecced1ff2941eaa643 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Wed, 22 Jun 2016 22:47:25 +0100 Subject: [PATCH] Allow Giftcard to do not have customer assigned (#689) --- application/controllers/Giftcards.php | 2 +- application/views/giftcards/form.php | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/application/controllers/Giftcards.php b/application/controllers/Giftcards.php index 6c8aeec50..26418a765 100644 --- a/application/controllers/Giftcards.php +++ b/application/controllers/Giftcards.php @@ -79,7 +79,7 @@ class Giftcards extends Secure_Controller 'record_time' => date('Y-m-d H:i:s'), 'giftcard_number' => $this->input->post('giftcard_number'), 'value' => $this->input->post('value'), - 'person_id' => $this->input->post('person_id') + 'person_id' => $this->input->post('person_id') == '' ? NULL : $this->input->post('person_id') ); if($this->Giftcard->save($giftcard_data, $giftcard_id)) diff --git a/application/views/giftcards/form.php b/application/views/giftcards/form.php index 0383150ac..98e89b333 100644 --- a/application/views/giftcards/form.php +++ b/application/views/giftcards/form.php @@ -55,17 +55,22 @@ //validation and submit handling $(document).ready(function() { - var fill_value = function(event, ui) { + $("input[name='person_name']").change(function() { + if( ! $("input[name='person_name']").val() ) { + $("input[name='person_id']").val(''); + } + }); + + var fill_value = function(event, ui) { event.preventDefault(); $("input[name='person_id']").val(ui.item.value); $("input[name='person_name']").val(ui.item.label); }; - var autocompleter = $("#person_name").autocomplete( - { + var autocompleter = $("#person_name").autocomplete({ source: '', - minChars:0, - delay:15, + minChars: 0, + delay: 15, cacheLength: 1, appendTo: '.modal-content', select: fill_value, @@ -73,11 +78,9 @@ $(document).ready(function() }); // declare submitHandler as an object.. will be reused - var submit_form = function() - { - $(this).ajaxSubmit( - { - success:function(response) + var submit_form = function() { + $(this).ajaxSubmit({ + success: function(response) { dialog_support.hide(); table_support.handle_submit('', response);