vtfuture / BForms

Bootstrap Forms for ASP.NET MVC
MIT License
62 stars 33 forks source link

Problem with BsControlType.Upload #193

Closed jaimestuardo closed 9 years ago

jaimestuardo commented 9 years ago

Hello,

I have a BsControlType.Upload property in my model:

    [Display(Name = "Check List", Prompt = "Suba la foto del check list")]
    [BsControl(BsControlType.Upload)]
    [Required]
    public string CheckList { get; set; }

And in my view, I have,

     @Html.BsTextBoxFor(s => s.CheckList, new { type= "file", @class= "bs-file" })

My attributes definition works, but adding the attributes, not replacing them, causing finally the control to be rendered as:

       <input type="file text" value="" placeholder="Suba la foto del check list" name="CheckList" id="CheckList" data-val-required="El campo Check List es obligatorio." data-val="true" class="bs-file form-control bs-text input-validation-error">

I have seen the source code and I think the problem is in the ApplyTextBoxAttributes method in TextBoxExtensions file.

I tried to recompile the solution, but it was not possible, so that i could not modify that code fragment.

Regards, Jaime

cristipufu commented 9 years ago

solved by 1d45307e90f0a1c623176e3ee58f4a282241804c

You can see an example on the register page (we added an input type file)

jaimestuardo commented 9 years ago

It looks pretty, however, it does not show how to achieve that. I have checked and rechecked the tabs that appear below the form, but I don't see anything about Avatar control (I checked Models, Views and Controllers tabs)

cristipufu commented 9 years ago

I forgot to update the documentation.

Basically, you need to do this:

Model:

[BsControl(BsControlType.Upload)]
public HttpPostedFileBase Avatar { get; set; }

View:

<div class="input-group">                    
        @Html.BsInputFor(m => m.Avatar)
        @Html.BsValidationFor(m => m.Avatar)
</div>

JS (use the ajax wrapper and form parser):

var $form = $('.js-form');
var data = $form.parseForm();

$.bforms.ajax({
   data: data,
   url: 'controller/action'
});
jaimestuardo commented 9 years ago

I have done it, but this error occurs:

"The CheckList of type bs-file does not match an input element".... and in fact, I saw the source code and that error message appears when no case statement is matched, and in this case BsControlType.Upload is not matched.

This is how I am using CheckList control:

            <div class="col-lg-12 form-group @Html.BsValidationCssFor(m => m.CheckList)">
                @Html.BsLabelFor(s => s.CheckList)
                <div class="input-group">
                    @Html.BsInputFor(s => s.CheckList)
                    @Html.BsValidationFor(s => s.CheckList)
                </div>
            </div>
cristipufu commented 9 years ago

Update your nugget package (or source files), we fixed it in today's commits.

jaimestuardo commented 9 years ago

hehehe.. thanks... I will do it right now