user655334
user655334

Reputation: 1015

clear the form fields using jquery unform plugin

I'm using jQuery uniform plugin for forms. But the problem is, how do I clear the 'file' input?

I am using:

$("[name=radio]").removeAttr("checked");
$.uniform.update(".colorPicker"); 

for clearing the radio boxes.

Also using,

$("#file_upload").replaceWith("<input type='file' id='file_upload' name='file_upload'>").html(); 

to clear the file input.

Upvotes: 0

Views: 718

Answers (4)

Displee
Displee

Reputation: 730

let input = $('input[name=file_input]');
input.val('');
$.uniform.update(input);

Works 100%.

Upvotes: 0

mohanrajt
mohanrajt

Reputation: 152

You can set the value of the field by using val() method of jQuery api. So the code is shown below:

$("#test1").on("click", function(){
       $("#test").val("");
});

Upvotes: 0

Snake Eyes
Snake Eyes

Reputation: 16764

Try sample HTML

<input type='file' name='item1' id="test" />
<input type='button' name='item2' id='test1' value="Empty"/>

javascript:

$(function(){
    $("#test1").on("click", function(){
       $("#test").replaceWith('<input type="file" name="item1" id="test"/>');
    });
});

demo: http://jsfiddle.net/dYEBW/

Means using your code (Update):

$("#file_upload").replaceWith("<input type='file' id='file_upload' name='file_upload'>");

Upvotes: 1

GautamD31
GautamD31

Reputation: 28753

Have you tried with

$("#file_upload").empty();

Upvotes: 0

Related Questions