⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Pressing enter clears date field



tomvsi
  • profile picture
  • Member

Posted 24 April 2012 - 16:53 PM

I just recently started using GroceryCrud and am loving it.

I have run into an issue:

In an edit screen (or add screen) I have a date field and several text input fields. I select the date and then tab to the next input field. I type information into the field (it doesn't matter if it's the immediate next field or down the list) and then accidentally hit the "Enter" key instead of tabbing to the next field. The date field is cleared.

Is this a known issue? Any workarounds?

Thanks.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 24 April 2012 - 20:56 PM

You are the first person to mention it and it was let's say a small bug. When you add a date and you press tab the focus will go to the button clear so if you press the enter button it will just press the clear button of the date. So I fixed that as it was really easy (just adding a tabindex=-1) . You can see the changes at: https://github.com/s...250ce9d62112bcd

Thank you to mention it.

lherlaar
  • profile picture
  • Member

Posted 27 April 2012 - 13:56 PM

Are you sure the tabindex is supposed to fix it? I replaced application/libraries/grocery_crud.php bij the new version on github but I'm still having this issue. I also cleared the cache etc. just to be sure. Removing the buttons solves the issue, but that's a rather blunt approach.

Thanks.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 27 April 2012 - 19:03 PM

I am sorry but can you please send me printscreens (press the button "More Reply Options" to the forum for that) of what you are doing exactly? I really cannot reproduce your problem. I want you to show me something like the example at my post: http://www.grocerycr...ndpost__p__1490 if it's possible.What grocery CRUD version do you use?

Also make sure that the form is cleared EVERYTIME you insert something. So at the add form it is normal to clear all the form when you press the enter button. The enter button is a shortcut to save faster at your form. So you don't need to press the submit button. If you press enter at any input of the default form it has to be like saving the form.

So for example if you have:

[attachment=139:image-1.png]

and you press enter it is normal to insert the data and clear the form like the image below:

[attachment=140:image-2.png]

But the clearing form doesn't suppose to happen at the edit form. Are you sure that only the date field is cleared?

lherlaar
  • profile picture
  • Member

Posted 27 April 2012 - 20:38 PM

Hi Johnny,

Here are the screenshots you requested (using the new Dutch language file :) ).

I have 2 date fields. Initially they are empty:

[attachment=141:enter1.png]

Then I start entering a date to each of those, using the datepicker, as usual:

[attachment=142:enter2.png]

So far so good, all fields that need data are entered:

[attachment=143:enter3.png]

Now I go to one of the other fields (could be any one of them, I just chose the one below the date fields here, but behavior is the same for all the other fields as well, even the date fields themselves):

[attachment=144:enter4.png]

And finally, if I press enter, one of the date fields becomes empty:

[attachment=145:enter5.png]

When pressing enter, I don't get the "data saved" message and all the other fields keep their contents. I have this behavior only for this form with the two date fields. On other forms without dates the fields get cleared and I see the "data saved" message. I'm using v1.2.1.1 and also tried the v1.2.2 lib file.

I hope this enables you to reproduce the issue.

Thanks!

lherlaar
  • profile picture
  • Member

Posted 27 April 2012 - 20:50 PM

Oh, and one more thing:

If I remove the buttons altogether, by removing the following line from the grocery_crud lib file:

<button class='datetime-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</button>

then I get the expected behavior with the "saved data" message:

[attachment=146:enter6.png]

[attachment=147:enter7.png]

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 28 April 2012 - 11:18 AM

Yes this will help a lot to reproduce the bug. I reopen the issue just to remind me that I have to deal with it. For any news I will inform you as soon as possible.

Thank you for making so specific the problem.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 30 April 2012 - 23:48 PM

I fix the problem the solution is here: https://github.com/s...3c7bb7362c9fd4f

I just want to share my knowledge with you because I don't want to believe that I just lose 1.5 hours of my life JUST to change the "button" to "a" .
So after a big research I find that the actual reason that happens is that the buttons are actually REALLY triggered with a click. So for example if you press enter and you see that the form is submitted automatically it doesn't trigger the event "submit" it is just "clicking" the FIRST submit button (in our case just button) and the form is sent.

So that's why if you have in a simple html form if you have:


<form action="">
<input name="test">
</form>


and you press enter at the input value NOTHING happens, but if you have:


<form action="">
<input name="test">
<button />
</form>


and you add a text at the input and just press ENTER the form is submitted as normal.

lherlaar
  • profile picture
  • Member

Posted 01 May 2012 - 00:36 AM

Hi Johnny,

I applied the change and can inform that this issue has been solved. These few bytes really make a difference... Good to know that form submission is actually a click event on the first button. Thanks for sorting this out!

tomvsi
  • profile picture
  • Member

Posted 01 May 2012 - 13:13 PM

Thanks for the fix.