Jquery Uniform Update doesn't work
Asked Answered
S

5

7

I'm using jquery uniform on one of the project I'm working on. Since this is admin panel, I truly don't have option to show. I will explain my problem

What I'm trying to do is quite simple. I'm adding some form elements (like select, check box, text input) to the page with ajax.

Every single thing works except re-styling those dynamically added form elements.

function step2 () {
    $.post( siteUrl + "includes/ajax/members/add-subscription.php?do=step2", $("#selectedSubscribers").serialize(), function( data ) { 
        $('.step2_content').html(data);
        $.uniform.update(); 
    });
 }

Anyone experienced similar problem? Even my onClick, onChange functions are working without a problem (dynamically added form elements), it is just, $.uniform.update(); doesn't seem to work.

I thought processing data could take longer time so $.uniform.update(); is called before data is processed so I tried $.ajax with async: false with no luck.

I will be glad if anyone who experienced such problem or who knows the solution could help me out with this problem.

Thank you in advance.

Sawmill answered 23/10, 2011 at 18:13 Comment(0)
T
14

When $.uniform() is first called, it collects all the specified elements into an internal array of affected elements. When you call $.uniform.update() it simply restyles those elements that were already collected.

To add additional elements, you may need to call $.uniform() again, passing a selector identifying only those new, dynamically added elements.

Table answered 23/10, 2011 at 18:23 Comment(1)
No idea why but this worked $( "select, input:checkbox, input:radio, input:file").uniform(); $.uniform.update(); without .update() still doesn't work and I don't get the point why do I have to use .update() after adding elements to the uniform.Sawmill
M
5

for load() if fix promblem

$('#dialog').load(url + ' #forload', function() {$('#dialog').find('select').uniform(), $('#dialog').find('input:checkbox').uniform()})
Materialize answered 19/3, 2012 at 12:45 Comment(1)
Thank you--I was having a problem getting uniform to style a select element after using .load() and this totally fixed it for me.Semiramis
B
2

Have you tried this?

$.uniform.update("#select_element_id");

In my case, the problem was solved.

Being old the version of uniform, may cause your problem.

Blessington answered 19/6, 2013 at 12:46 Comment(0)
S
1

Another solution may be this

setTimeout("$('.uniform_element').uniform();",200);

200 or a higher number may need.

Shriver answered 19/12, 2012 at 17:32 Comment(2)
This solution is actually recommended per the uniform read and relevant issue #270Farland
This solution actually worked. In my case checkbox(s) were inside drop downHelms
F
1

Try this:

   $('.elementClass').uniform();
Firewood answered 23/1, 2014 at 5:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.