logo
down
shadow

data-* attributes do not work with Html::a() in Yii 2


data-* attributes do not work with Html::a() in Yii 2

By : user2185473
Date : November 21 2020, 04:01 AM
Hope this helps Okay, since I have used Html::a inside a GridView column, you will have to change the output format of that column. html will not work for data attributes, so you will need to switch to raw:
code :
[
    'label' => 'Actions',
    'format' => 'raw',
    'value' => function($model) {
        return Html::a('Link', ['some/route'], [
            'class' => 'btn btn-lg btn-primary',    // WORKS
            'style' => 'padding: 100px;',           // WORKS
            'data-id' => 123,                       // WORKS
            'data' => [
                'id-second' => 123,                 // WORKS
            ],
        ]);
    },
]


Share : facebook icon twitter icon
How do I get Html.RouteLink() to work with a RouteValueDictionary while passing Html Attributes?

How do I get Html.RouteLink() to work with a RouteValueDictionary while passing Html Attributes?


By : JayDee101
Date : March 29 2020, 07:55 AM
it fixes the issue The problem is there was no overload for Html.RouteLink(string, RouteValueDictionary, object)
So I needed to pass my html attriute as a dictionary like this:
code :
    <%: Html.RouteLink(
        "link",
        item.RouteValues, 
        new Dictionary<string,object>{{"title", "title text"}}) %>
Html.EditorFor, data annotations and html attributes for DateTime field

Html.EditorFor, data annotations and html attributes for DateTime field


By : user3690836
Date : March 29 2020, 07:55 AM
seems to work fine In order to have the DataAnnotations flow through, you must change your Editor Template to use TextBoxFor instead of TextBox, like so:
code :
@ModelType DateTime
@Html.TextBoxFor(Function(m) m, New With {.class = "date"})
MVC Html ActionLink with Twitter Bootstrap doesn't work with html attributes for javascript integration

MVC Html ActionLink with Twitter Bootstrap doesn't work with html attributes for javascript integration


By : crazymouse
Date : March 29 2020, 07:55 AM
How can i make 2 id attributes work on the same HTML element?

How can i make 2 id attributes work on the same HTML element?


By : フルフル
Date : March 29 2020, 07:55 AM
hop of those help? Don't use more than one id-attribute on the same DOM element (its no valid HTML otherwise)! You should use another attribute for your JavaScript approach. For Example:
code :
<input type="button" id="button1" class="jsReset" value="Subscribe">
<input type="button" id="button1" data-js-id="reset" value="Subscribe">
document.getElementById('button1')
jQuery('#button1') // if you already use jQuery
Can I add custom attributes to button html. Will it work in all browsers

Can I add custom attributes to button html. Will it work in all browsers


By : xjet
Date : March 29 2020, 07:55 AM
around this issue Yes you can use jquery .data for adding custom attribute.
It can be used to add any custom arbitrary data
shadow
Privacy Policy - Terms - Contact Us © bighow.org