data- attribute in dart dynamic elements - dart

I am creating some html elements dynamically with code such as
new ButtonElement()
and its easy to add classes like
..classes.add('dropdown-menu')
I want to add the following html to it
data-toggle="dropdown"
but dart doesn't allow me to do so. If I add a new ElementHtml like
new ElementHtml('<button data-toggle="dropdown"></button>')
it says it's invalid. I need it for my bootjack dropdown selector.
Any ideas on this?

I think you need a NodeValidator that has the data-toggle attribute enabled (see also Dart, why does using innerHtml to set shadow root content work but appendHtml doesn't?)
What you can do without NodeValidator is
new ButtonElement()..dataset['toggle'] = 'dropdown';

Related

How to set style when BeginForm html helper is created?

I use in my mvc5 project Html.BeginForm() html helper.
I need to create the element and set style = "pedding:12px!important"
I saw many examples in the web but the are all uses class, I dont want to declare class I just need to put style as is.
How can I implement it?
You need this overload.
Html.BeginForm("MyAction", "MyController", FormMethod.Post, new { style = "padding:12px" })
Not sure why you would add !important to the CSS if the rule is defined on the element itself. Doesn't that override any CSS anyway?
The use of !important should be reserved for overriding other "!important" rules from libraries you cannot modify.

How to get Ember compoment's "ID" attribute?

I am using a ember components in a recursive manner and im going to make particular components as draggable in jquery-ui. so,i need to get its corresponding view id like "ember143" for the following HTML view,
<div id="ember143" class="ember-view"></div>
is there a way to get the id attribute?
NOTE: i know i cant set a unique class name to get its view element by
var Component = Ember.Component.extend({
classNameBindings: ["uniqueClassName"],
uniqueClassName: 'class143'
});
if it is possible, how to do that?
Ember Component has a elementId property which returns the id of the element in the DOM.
so you can get the component's id using `this.get('elementId').
More info here:
http://emberjs.com/api/classes/Ember.Component.html#property_elementId

What is the point of mvc Label helper?

I understand that the actionlink uses the route tables to display the corrert link, but what advantage does the Html.Label helper offer?
The label helper doesn't do a whole lot. Its function is to encapsulate a small bit of markup so you don't have to write the HTML by hand each time. It also provides intellisense. This is helpful when you change a value in your model, then you don't have to go back and edit your view. Ideally, your label text and target should be driven from your ViewModel using LabelFor and not defined in your HTML.
If you look at the source code for the Label helper, it does the following:
//Create a new <label> element
TagBuilder tag = new TagBuilder("label");
//Add the attribute "for" with the id value of the target <input>
tag.Attributes.Add("for", TagBuilder.CreateSanitizedId(html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName)));
//Set the label text <label>My Text</label>
tag.SetInnerText(resolvedLabelText);
//Merge any attributes specified in the htmlAttributes arguement (ex: class="style")
tag.MergeAttributes(htmlAttributes, replaceExisting: true);
//Write the output rendering, this is not a self closing tag </label>
return tag.ToMvcHtmlString(TagRenderMode.Normal);
Note: I referenced LabelFor here instead of Label. However, the LabelFor helper actually calls the Label helper internally. The LabelFor helper is best practice.
Just read this from an mvc book
"Finally, it’s worth noting that these HTML helper methods automatically HTML-encode the field values
that they render. That’s very important; otherwise, you’d have no end of XSS vulnerabilities laced
throughout your application."
Pro
ASP.NET MVC 2
Framework
Steven Sanderson
Html.Label and Html.LabelFor are wrappers around the HTML label tag. One of the core "hidden" features of this tag is that, if it's associated with an input control, you can set focus to the associated control by clicking on the label. This isn't as big a deal for textboxes and things like that, but using it with your checkboxes and radio buttons will be a significant usability boost for your users - clicking the label has the same effect as clicking inside the control itself.

Pass multiple html parameter with BeginForm

I need to send parameters with values ​​in a BeginForm html.
Example:
# using (Html.BeginForm ("Create", "IncomeDeclaration", new {declarationAmount = document.getElementById ("element"). value}))
This value I can not get from the Model, as it is not found in the model.
I've tried several ways and nothing worked. If you could change the content of a ViewBag that'd be great.
I appreciate your support.
You can't mix and match Javascript (document.getElementById ("element")) with the C# form declaration. If you want a value submitted with the form, you should add a relevant form element inside the form declaration. If you don't want a regular form element (eg. a textbox), you can use a "hidden" input field. If you want, you can dynamically populate the hidden field using javascript.

ASP.NET MVC Ajax: How to update an Ajax.ActionLink itself on-click

I have a page that displays a list with a of elements with a large number of elements, each of which has a boolean property, representing an Enabled and a Disabled state.
I need to provide the user with a link for each list item, and the link text must show the opposite status (so if the item is enabled, the link text must display 'Disable').
When the user clicks the link for a Disabled, the corresponding link text for the item must change to 'Enable' (and vice versa).
I would like to NOT reload the entire list for each click, just the text of the ActionLink itself, so my question is:
Is it possible to update just an ActionLink itself when the user clicks the link, or do I have do handle this using custom javascript?
As far as I remember, you can add HTML attributes to the "a" tag by newing up an anonymous class as the last param on most overloads.
Off the top of my head this can be written like the following:
Html.ActionLink("Name", "Action", "Controller", new { #class = 'updateId' });
(You may be able to do this with an ID which would be preferable over a class - if not just use a unique class name to avoid updating multiple items.)
Then you can use javascript to access the class "updateId" and change the inner html.
In the case of jQuery:
$("a.updateId").html("NewName");
This can be done with a custom user control contained within the element to update. A writeup of the solution can be found here. No custom client-side scripting is necessary.

Resources