Search code examples
javascriptjquerytwitter-bootstraptwitter-bootstrap-2bootstrap-file-upload

Bootstrap Filestyle - Changing button text for file field doesn't work


I would like to change button text for file field in Bootstrap Filestyle plugin in Bootstrap 2.3.2, but it doesn't work and text of button is still default. I create file field by replacing element in jquery and tried to set text by attribute data-buttonText or method $("#changeAccountsSourceModal :file").filestyle('buttonText', 'Choose address');

jsfiddle sample

File field

$("#changeAccountsSourceModal .form-horizontal").replaceWith("<input type=\"file\" class=\"filestyle\" data-input=\"true\" data-buttonText=\"Choose address\">");

$("#changeAccountsSourceModal :file").filestyle();

Solution

  • Just tried it out by passing the option in an object on initiating filestyle, works.

    $("#changeAccountsSourceModal :file").filestyle({buttonText: 'Choose address'});
    

    Ironically when you try to change the vaule afterwords the text just gets added to the button.

    $("#changeAccountsSourceModal :file").filestyle('buttonText', 'Choose address');
    

    fiddle

    working fiddle