Closed johnwc closed 8 years ago
I have spent a great deal of time and effort considering possibilities for a better support for Editor feature in BMVC. In a lot of cases people's requests are not feasible due to the Editor's nature. However, I was able to add ShowValidationMessage()
extension helper.
Let me know if you have more feature requests, but bare in mind, I might not be able to add that.
Please get latest.
It's not adding the form-control style to the class of the input element.
<div class="form-group">
<label class="control-label col-lg-6" for="Price">Price<span class="required" aria-required="true" style="visibility: hidden;">*</span> </label>
<div class="col-lg-6">
<input name="Price" class="text-box single-line" id="Price" type="text" value="$300"> </div> </div>
Are you using MVC5?
Yes
Sent from my iPhone
On Jan 12, 2016, at 10:48 AM, Dmitry A. Efimenko notifications@github.com wrote:
Are you using MVC5?
— Reply to this email directly or view it on GitHub.
In general I suggest developers to avoid .EditorFor helper when working with BMVC. Here are couple references why:
https://github.com/DmitryEfimenko/TwitterBootstrapMvc/issues/41#issuecomment-22301292
https://github.com/DmitryEfimenko/TwitterBootstrapMvc/issues/282#issuecomment-40174604
In short - EditorFor is for custom templates and complex types. There is no way for BMVC to know what template you are using for a given type and what custom logic it has. BMVC cannot alter templates used by EditorFor.
This limits things you can do with EditorFor when using BMVC. However, if all you need is to add a class to the input, in MVC5 you can do it. Use .AdditionalViewData()
extension method:
@f.FormGroup().EditorFor(m => m.Price)
.AdditionalViewData(new { htmlAttributes = new { @class = "form-control" } })
.ShowValidationMessage(true)
So, if I can do that, why not just do that internal before you return from the EditorFor?
Templates used for any given type can be customized by a developer. I'm not sure what exactly will happen to these custom templates if I start messing with AdditionalViewData implicitly.
However, I have done just that in the latest build (get latest). Lets see how it'll go. If I suddenly start receiving lots of complains from users I'll have to revert this change. Lets see...
When calling EditorFor it doesn't give any functionality like the TextBoxFor method. We need to be able to call EditorFor and still use the sub-methods to control the Bootstrap output for the control.
Example: This is what we have today, but it doesn't use all the MVC data annotations like formatting, etc...
@f.FormGroup().TextBoxFor(m => m.Price).ShowValidationMessage(true)
We need it to work like so, and have the ability to call the other bootstrap methods.@f.FormGroup().EditorFor(m => m.Price).ShowValidationMessage(true)