I wonder if there way to customize td inner HTML of grid, for example I need to bound some field, and make clickable.
Didn't found any other way, except adding onclick attribute.
Columns(column => column.For(x => x.GotToPursue).Attributes(#onclick => "align-right")
Any suggestions?
The only way to this I've found is to write your on extension method, working with already formed innerhtml to change it.
Related
I have this validation message for a field in MVC view outside the begin form. However it is not displaying that.
#Html.ValidationMessageFor(m => m.OldPassword)
Is there any possible way I can achieve this? Since I don't wanna use a Jquery or Javascript function just to validate this.
Keep the validation message inside the form with a Div tag.
Make the Div display none.
On button click, check the IsValid property of the form
If in valid, then copy the HTML() of the Div and put it into another div which will be outside the form.
Its not a clean solution, but the trick will work
ValidationMessageFor only works if the fields / Controls are inside the form post action for that controller. Otherwise need to do separate methods like JavaScript / Ajax / ViewBag to get the error.
It only works if #Html.ValidationMessageFor(m => m.Property) is inside the form. However, I managed to find a workaround that also updates the outside div when there are element changes, i.e., when the error messages change without re-submitting the form:
Place a <div id="outside-form"></div> outside your form.
Place a <div id="inside-form" style="display:none;"></div> inside your form, which contains all #Html.ValidationMessageFor(m => m.Property) statements.
This is the nasty part, in your jquery.validate.js, find the following:
form: function() {.....} and just before the function return add $("#outside-form").html($("#inside-form").html());. This ensures that your outside-div will be updated every time the whole form is validated.
element: function( element ) {.....} and just before the function return add $("#outside-form").html($("#inside-form").html());. This ensures that your outside-div will be updated every time each form element is validated.
That's it! I was wondering if there's some way of extending the form and element objects without changing the .js file itself.. do you have any clue about this?
I can have tags inside option tags, and it works (don't know if it's valid HTML4/5, but it works in Firefox at least):
<select>
<option><i class="icon-plus"></i>Add item</option>
<option><i class="icon-remove"></i>Remove item</option>
<option><i class="icon-edit"></i>Edit item</option>
</select>
I'm placing Bootstrap/FontAwesome webfont icons in those option tags.
But I'm using MVC4/Razor, and I can't get the correct syntax to make it render properly. It encodes all those inner tags and I get <, >, etc.
This is what I'm doing:
// first I make a new list with the icons inside
var items = Model.Items.Select(q => new SelectListItem() {
Selected = q.Selected,
Text = "<i class=\"icon-add\"></i>" + q.Text,
Value = q.Value
});
// then render the dropdown
Html.DropDownListFor(m => m.SelectedItem, items, "All")
How do I get this working?
You can't do this out of the box. Depending how often you need to use it - I personally would recommend doing it manually via a loop.
If you want, you could write an extension method/helper for the drop down list.
I found a similar example here, though this guy uses it to custom the 'select' tag, you'll want to custom the 'options' tag: Fun (?) with Linq Expressions in extension methods
Hope this helps.
OK I've selected an easy easy option...
Simply put the FontAwesome classes on the <option> tag instead of a nested child <i> tag. That way the markup is valid.
Of course this needs to be done manually in a loop.
I currently using ahDoctrineEasyEmbeddedRelationsPlugin to embed a Block form into a Page form.
All works well, but I'd like to hide the label of the embeddedRelation.
I've created a 'homepage-main-top' Block within the Page form in the admin, now when editting this Page, I now see 'homepage-main-top' is randomly appearing before the embedded block relation
Looking at the plugin docs, there doesn't seem to be anything relating to removing/hiding this:
http://imageshack.us/photo/my-images/197/relation.png
Does anyone know how to not display this?
Thanks
I've been struggeling with somewhat the same problem, only I needed to style the label instead of hidding / stripping it.
From what I've found out there is no simple way to manipulate the label of the embedded form, but I figured the following 'hack'.
The embedRelation method accepts a inner- and outer-decorator parameter. You can use these to wrap extra markup around the label and the embedded form. You can then use CSS to hide the label using a specific id / css class.
By openning tags in the outerdecorator and closing them in the inner decorator you can wrap the label in a tag (which is rendered inbetween the two). It is kind of tricky to make sure your HTML is still valid.
I know this is kind of a crappy solution but I haven't found a better way up until now.
Add this line to your parent form:
$this->widgetSchema['EmbeddedFormName']->setLabel(' ');
If the above doesn't work, try using the 'newFormLabel' option (from the plugin's documentation).
$this->embedRelations(array(
'RelationName' => array(
// ...
'newFormLabel' => ' ',
// ...
),
// ...
));
I am tinkering with the MVCContrib Grid and am stuck on how to format a row of data in the grid based on the data.
For example, say we have a grid of products, where each product has data fields like name, price, and discontinued. I'd like to highlight all product rows that are discontinued.
One workaround would be to use jQuery on the client-side to apply a CSS class to those rows where the discontinued cell is TRUE, but that seems like a brittle solution. I'm hoping there's a way to do it on the server-side via the Html.Grid method call.
Thanks
Hello Scott: Try something like the following to add RowAttributes -
#Html.Grid(Model)
.WithModel(new CustomerGridModel())
.Sort(ViewData["sort"] as GridSortOptions)
.Attributes(id => "grid", style => "width: 100%;")
.RowAttributes(data => new MvcContrib.Hash(
#class => data.Item.Discontinued ? "discontinued" : ""))
This will add a class attribute to the tr element. Then, create a class along the lines of:
tr.discontinued td {background-color: red;}
Sorry for the long code snippet...
i have text like this
div bla-bla end div
i need to get only 'bla-bla' without div, because of i need to call substring in controller only to text bla-bla not to div tags. is it possible
p.s. how to input tags here?
If you have jquery you can access inner html by calling ( for example ):
$("#idofthediv").html()
to set the conntent of the div:
$("#idofthediv").html('some html')
document.findElementById(..).innerText;
Take a look at using a Regular Expression.
There is a sample of what you want to do at Regular Expression Examples. It's the first sample in the section titled "Grabbing HTML Tags" near the top of the page.