I am looking at MVC3 razor examples and seeing html.editorfor being utilized and also asked about a lot on this forum. Why can't i use html.textboxfor and passwordfor? Thanks
EditorFor has the advantage that it will try to render an editor associated to the data type.
For example: If you design your own Editor Templates they will automatically be rendered based upon the property's type or UIHint
A useful editor template might be one that generates a date picker when the property's type is a DateTime.
There are some other scenarios as well where the 'smart' EditorFor will generate the 'best' editor for the property such an example is when it renders a <textarea> when tagging the property with MultilineText
Using TextBoxFor and PasswordFor are perfectly fine for those cases where you don't require 'a special editor'. It might even simplify your life when having to set HtmlAttributes.
Ref Differences between Html.TextboxFor and Html.EditorFor in MVC and Razor for clear the doubt about this..
The HtmlTextboxFor always creates a textbox (<input type="text" ...).
While the EditorFor looks at the type and meta information, and can
render another control or a template you supply.
For example for DateTime properties you can create a template that
uses the jQuery DatePicker.
if you decide to change something to the aspect of how your textboxes are rendered like wrapping them in a div you could simply write a custom editor template (~/Views/Shared/EditorTemplates/string.cshtml) and all your textboxes in your application will automatically benefit from this change whereas if you have hardcoded Html.TextBoxFor you will have to modify it everywhere.
Related
I have a Kendo Grid that uses pop up editing due to the large amount of fields in my model. However the model does not use friendly. When I bind a column, I can simply use .Title("Some Title") to make the column have a friendly name. When I pop up the editor, I get the names from my model. I have looked at this demo by telerik http://demos.telerik.com/aspnet-mvc/grid/editing-popup that clearly shows the pop up using friendly names and not the bound names. I just have no clue how they are doing it. Any help is appreciated.
They are probably using the [Display(Name="Some Nice Title")] on the properties. part of the Data Annotations collection. (That's what I usually do with pop up editors)
Then using the #Html.LabelFor(m => m.[Your Property here]); within the editor window itself (if you are providing a custom template rather than getting the grid to create one for you)
I am assuming you are using the MVC wrappers so this should work perfectly fine.
If you can provide a cut down version of your model then I am sure I could add some example code for you. If this isn't clear enough.
I would kindly ask for your help :) From couple of days I am trying to achieve "linked" custom field in content editor and dropdown in page editor.
Basically I want to have dropdown in page editor and content editor which are responsible for a same thing.
In my c# code i have enums which represent directions. I created custom field which accepts assembly and class with overridden onload method and successfully populate dropdown values in the content editor. So far so good but i have no idea how to create dropdown which will represent the same functionality inside page editor.
So please give me any ideas...
Judging from your reply to my comment you need to think of the following: How is my field value being rendered onto a page?
If you are always using 1 control to do this then you just need to ensure that this control has 2 different rendering modes depending on the Context.PageMode
But as I understand it you want this dropdown to also appear when someone renders your custom field using a <sc:FieldRenderer>. In this case you'll need to look into the RenderField pipeline of Sitecore. There you find a processor called RenderWebEditing. Possibly through some manipulation here you can get your dropdown appear as you wish.
I have a view with a dropdown and a Rich Textbox. This view is associated with a model. I would like to make Rich Textbox field is required based on the value selected in dropdownlist.
is there any out of the box feature available in MVC3 to do this?
I have had similar requirements in the past, I solved them using FoolProof. It provides extra validation objects such as requiredIf etc.
Only issue I have had is with the JS file, it can be a bit buggy around dates and date handling, other than that, it is ace.
Foolproof site
I wish to create dynamic dropdown, meaning the value of the second dropdown changes with the change in selection on the first. I was looking through the Dojo docs and it seems there are 3 different widgets that I can use,
dijit/form/ComboBox
dojox/form/DropDownSelect
dijit.form.Select
Now I am confused as to which one should i use for creating Dynamic DropDowns?
You can choose anyone depending upon what extra features you want. While dijit.form.Select is your normal HTML select, combobox and filteringselect offer more features.
Follow http://kennethfranqueiro.com/2010/06/combobox-vs-filteringselect/ for a comparison between the two. You can also play with them to know how they work.
I had used FilteringSelect in my app for the same behavior as need.
Differences between dojo dropdown :
Select It is simple combobox like select in HTML with no validation
and not provide any search facility inside select options.
ComboBox It is pure form of combobox and name as ComboBox again it
will not provide any default validation but it provide search
facility within its options.
FilteringSelect It is an advance form of select have default
facility of validation and search facility. And it also has property
to take value as input tag take value in HTML.
In dojo you can also try custom validation which is provided inside dojox library. I hope it will help you.
I have a few complex GUI elements (like a custom calendar with many days that can be highlighted) that appear along with standard django form input fields. I want to process the data I/O from these complex forms along with the Django forms.
Previously I would use AJAX requests to process these custom GUI elements on my HTML form after the Django form was saved or rendered, but this leads to a host of problem and customized AJAX coding. What is a good way to handle complex interactions widgets in a Django form?
Not sure if I understand completely, but you could have the value of your UI saved into a hidden element on the form via javascript. This can either be done as they select the values in the UI or when they submit the form. Pseudo-code assuming JQuery using submit() to save before the submit data is sent:
$('#myForm').submit(function(){
// get the value of your UI
var calendarValue = calendarWidget.getValue()
// #calendarData is the hidden field
$('#calendarData').val(calendarValue)
})
This obviously requires JS, but so does using your UI element.
Your question is very vague so I suggest you read the Django documentation on writing a custom field and hopefully that will help you get started. You might also want to investigate writing a custom widget. Unfortunately the documentation is bit lacking on that, but a Google search brings up several useful blog posts, including this one.
You have three options depending on how you output your Django Form subclass to the HTML page.
The first doesn't involve Form at all. Any html form inputs will end up in request.POST, so you can access them there. True, they won't be bound to your Form subclass, so you would have to manually inject the value either using a custom form constructor, or by setting some property on your Form object after instantiating it with request.POST. This is probably the least desirable option, but I mention it in case your use-case really doesn't support anything else.
The second is an option if you manually output the form fields in your HTML (ie: using {{ myform.field }} rather than just {{ myform }}. In this case, make a hidden variable to contain the value of your calendar GUI tool (chances are, your GUI tools already offer/require one). Add this hidden field, with the right name and ID, to the Form subclass itself, making sure it has a hidden django form widget. If necessary, use javascript as Rob suggests to populate the hidden field. When the form is posted, it will get bound to your form subclass as normal because, this time, you have a field on your Form subclass with that name. The machinery for clean() will work as normal.
The third, and best option, is to write a custom django field; Andrew's post has the link. Django fields have the ability to specify js and css requirements, so you can automatically encapsulate these dependencies for any page that uses your calendar widget.