Skip to content
This repository

Fix select duplication #1129

Closed
wants to merge 1 commit into from

2 participants

Emmanuel Vella Thomas
Emmanuel Vella

Fix the select elements duplication in case of validation error.

Thomas
Owner

You are removing DOM inserting here, why ?
Can you explain how to reproduce the behavior ?

Emmanuel Vella

You are right, I should keep the inserted span. BTW there is still an issue with the following code :

target = jQuery('span', element);

If more than one span are in the element, the input (select) field will be duplicated because of this code :

jQuery(input).appendTo(target);

Let me update my PR.

Emmanuel Vella Fix select duplication
Fix the select elements duplication in case of validation error.
9dbd7d4
Emmanuel Vella

I just updated my PR. I wrap the select with a span, then I choose this span as qtip target.

Thomas
Owner

Can you tell me how to reproduce this issue ?

Emmanuel Vella

This happens on sonata_type_model form fields. I reproduced the issue in the sandbox.

In the PostAdmin, add an empty_value and remove the required option to the author field :

->add('author', 'sonata_type_model', array('empty_value' => '', 'required' => false))

Then in the Post entity validation.xml file, set the author to be not null :

<getter property="author">
    <constraint name="NotNull" />
</getter>

Now create (or update) a post without selecting an author : the field should be here 3 times, making update impossible.

sonata_type_model

Thomas rande closed this March 27, 2013
Thomas
Owner
rande commented March 27, 2013

cherry picked and merged into 2.1/master

Emmanuel Vella

Thanks

Emmanuel Vella EmmanuelVella deleted the branch March 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 29, 2013
Emmanuel Vella Fix select duplication
Fix the select elements duplication in case of validation error.
9dbd7d4
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 4 additions and 5 deletions. Show diff stats Hide diff stats

  1. 9  Resources/public/base.js
9  Resources/public/base.js
@@ -45,13 +45,12 @@ var Admin = {
45 45
             var target;
46 46
 
47 47
             /* Hack to handle qTip on select */
48  
-            if(jQuery(input).is("select")) {
49  
-              jQuery(element).prepend("<span></span>");
50  
-              target = jQuery('span', element);
51  
-              jQuery(input).appendTo(target);
  48
+            if(jQuery(input).is('select')) {
  49
+                input.wrap('<span></span>');
  50
+                target = input.parent();
52 51
             }
53 52
             else {
54  
-              target = input;
  53
+                target = input;
55 54
             }
56 55
 
57 56
             target.qtip({
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.