my kendo toolbar has items using template and overflowtemplate, e.g.
template:
<label id='piName'>Hello</label>
overflowtemplate:
<label id='piName'>Hello</label>
In runtime, based on conditions, I want to update the words in the overflow popup (say from Hello to Good) Anyone know who to do it in js/jquery? Thanks
This is not kendo specific, just DOM manipulation. You have already given the element an id, so just select for that and update the content:
$("#piName").text("Good");
As an aside, elements ids should be unique for html to be semantically correct so I would recommend using a different one in each template. Or perhaps you can use a class which does not need to be unique and additionally gives you the option to style the label with css:
<label class='toolbar-label'>Hello</label>
$(".toolbar-label").text("Good");
Related
I want to check if a postgresql database contains a specific value. If it is true I want to hide a HTML . Is this possible?
Can I hide elements with CSS & JS, or what should I use to hide the div?
Also, How would we add it in the Div like a NgIF statement
Thanks!
What you can do, vs what's best and the Angular way:
I assume you expect to have an AJAX call similar to:
$http.databaseAPI.get().subscribe(s => { this.hasValue == s.IsActive; });
Then, you could do a few things:
<div *ngIf="hasValue"></div>
Removes element from the DOM. Potentially very performance detrimental if overused.
<div [hidden]="!hasValue"></div>
Hides the element in the DOM.
<div [ngClass]="{'hideme': hasValue === false}"></div>
Changes the CSS based on an expression, and would require supporting CSS to hide the element.
Welcome to stackoverflow. You can get all that information from angular docs
*ngIf removes/adds the html elements from the html tree.
<div *ngIf="condition">Content to render when condition is true.</div>
This is the markup for the checkbox using material-design-lite:
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox">
<input type="checkbox" id="checkbox" class="mdl-checkbox__input" />
<span class="mdl-checkbox__label">Checkbox</span>
</label>
Problem is, that the labels for is connected to the inputs id.
So when I add dynamically a new checkbox, I have to also add an id. But how do I find out which Id to add? Wouldn't it be a problem, when I am later going to add these rows into a database?
Here is the working example:
http://codepen.io/anon/pen/QjNzzO
Notice the checkbox of the new task you add
As mentioned, you need to upgrade the element. You could call componentHandler.upgradeDom() instead of componentHandler.upgradeElement().
http://codepen.io/pespantelis/pen/pjbvBL
Material Design Lite will automatically register and render all elements marked with MDL classes upon page load. However in the case where you are creating DOM elements dynamically you need to register new elements using the upgradeElement function.
To upgrade all elements, use this code:
componentHandler.upgradeAllRegistered();
http://www.getmdl.io/started/index.html#dynamic
How Component Handler works?
My personnal approach is to create a component. I have a working one here in coffeescript and jade
Basically you need to call componentHandler.upgradeElements(el). Last time I checked this wasn't enough as it wasn't adding the ripple effect so you also need to upgrade the lastChild. Please note there's a difference with componentHandler.upgradeElement(el) and componentHandler.upgradeElements(el) which, if I recall correctly, walk deeply the dom.
About the problem with the id you should just use the $index. I updated the codepen so it solves your problem and I'll come back at you to help you with the style of the checkbox(which is not the question initially).
http://codepen.io/anon/pen/dYMBqj?editors=101
You need to call componentHandler.upgradeElement(el) after adding the checkbox to the DOM. I'm not familiar with vue.js, so I can't suggest the specific code change required, but this article seems like it has the answer.
What does data-toggle attributes do in Twitter Bootstrap? I couldn't find an answer in Bootstrap API.
I have seen a similar question before as well, link.
But it didn't help me much.
It is a Bootstrap data attribute that automatically hooks up the element to the type of widget it is. Data-* is part of the html5 spec, and data-toggle is specific to Bootstrap.
Some Examples:
data-toggle="modal"
data-toggle="collapse"
data-toggle="dropdown"
data-toggle="tab"
Go through the Bootstrap JavaScript docs and search for data-toggle and you will see it used in the code examples.
One working example:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Dropdown trigger</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li>Item</li>
</ul>
</div>
Any attribute that starts with data- is the prefix for custom attributes used for some specific purpose (that purpose depends on the application). It was added as a semantic remedy to people's heavy use of rel and other attributes for purposes other than their original intended purposes (rel was often used to hold data for things like advanced tooltips).
In the case of Bootstrap, I'm not familiar with its inner workings, but judging from the name, I'd guess it's a hook to allow toggling of the visibility or perhaps a mode of the element it's attached to (such as the collapsable side bar on Octopress.org).
html5doctor has a good article on the data- attribute.
Cycle 2 is another example of extensive use of the data- attribute.
For example, say you were creating a web application to list and display recipes. You might want your customers to be able to sort the list, display features of the recipes, and so on before they choose the recipe to open. In order to do this, you need to associate things like cooking time, primary ingredient, meal position, and so on right inside the list elements for the recipes.
<li>Borscht</li>
<li>Chocolate Mousse</li>
<li>Almond Radiccio Salad</li>
<li>Deviled Eggs</li>
In order to get that information into the page, you could do many different things. You could add comments to each LI element, you could add rel attributes to the list items, you could place all the recipes in separate folders based on time, meal, and ingredient (i.e. ). The solution that most developers took was to use class attributes to store information about the current element. This has several advantages:
You can store multiple classes on an element
The class names can be human readable
It’s easy to access classes with JavaScript (className)
The class is associated with the element it’s on
But there are some major drawbacks to this method:
You have to remember what the classes do. If you forget or a new developer takes over the project, the classes might be removed or changed without realizing that that affects how the application runs.
Classes are also used for styling with CSS, and you might duplicate CSS classes with data classes by mistake, ending up with strange styles on your live pages.
It’s more difficult to add on multiple data elements. If you have multiple data elements, you need to access them in some way with your JavaScript, either by the name of the class or the position in the class list. But it’s easy to mess up.
All the other methods I suggested had these problems as well as others. But since it was the only way to quickly and easily include data, that’s what we did.
HTML5 Data Attributes to the Rescue
HTML5 added a new type of attribute to any element—the custom data element (data-*). These are custom (denoted by the *) attributes that you can add to your HTML elements to define any type of data you want. They consist of two parts:
Attribute Name
This is the name of the attribute. It must be at least one lowercase character and have the prefix data-. For example: data-main-ingredient, data-cooking-time, data-meal. This is the name of your data.
Attribute Vaule
Like any other HTML attribute, you include the data itself in quotes separated by an equal sign. This data can be any string that is valid on a web page. For example: data-main-ingredient="chocolate".
You can then apply these data attributes to any HTML element you want. For example, you could define the information in the example list above:
<li data-main-ingredient="beets" data-cooking-time="1 hour" data-meal="dinner">Borscht</li>
<li data-main-ingredient="chocolate" data-cooking-time="30 minutes" data-meal="dessert">Chocolate Mousse</li>
<li data-main-ingredient="radiccio" data-cooking-time="20 minutes" data-meal="dinner">Almond Radiccio Salad</li>
<li data-main-ingredient="eggs" data-cooking-time="15 minutes" data-meal="appetizer">Deviled Eggs</li>
Once you have that information in your HTML, you will be able to access it with JavaScript and manipulate the page based on that data.
From the Bootstrap Docs:
<!--Activate a modal without writing JavaScript. Set data-toggle="modal" on a
controller element, like a button, along with a data-target="#foo" or href="#foo"
to target a specific modal to toggle.-->
<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
So many answers have been given, but they don't get to the point. Let's fix this.
http://www.w3schools.com/bootstrap/bootstrap_ref_js_collapse.asp
To the point
Any attribute starting with data- is not parsed by the HTML5 parser.
Bootstrap uses the data-toggle attribute to create collapse functionality.
How to use: Only 2 Steps
Add class="collapse" to the element #A you want to collapse.
Add data-target="#A" and data-toggle="collapse".
Purpose: the data-toggle attribute allows us to create a control to collapse/expand a div (block) if we use Bootstrap.
The presence of this data-attribute tells Bootstrap to switch between visual or a logical states of another element on user interaction.
It is used to show modals, tab content, tooltips and popover menus as well as setting a pressed-state for a toggle-button. It is used in multiple ways without a clear documentation.
The purpose of data-toggle in bootstrap is so you can use jQuery to find all tags of a certain type. For example, you put data-toggle="popover" in all popover tags and then you can use a JQuery selector to find all those tags and run the popover() function to initialize them. You could just as well put class="myPopover" on the tag and use the .myPopover selector to do the same thing. The documentation is confusing, because it makes it appear that something special is going on with that attribute.
This
<div class="container">
<h3>Popover Example</h3>
Toggle popover1
Toggle popover2
</div>
<script>
$(document).ready(function(){
$('.myPop').popover();
});
</script>
works just fine.
It is a Bootstrap defined HTML5 data attribute. It binds a button to an event.
Here you can also find more examples for values that data-toggle can have assigned. Just visit the page and then CTRL+F to search for data-toggle.
Bootstrap leverages HTML5 standards in order to access DOM element attributes easily within javascript.
data-*
Forms a class of attributes, called custom data attributes, that allow proprietary information to be exchanged between the HTML and its DOM representation that may be used by scripts. All such custom data are available via the HTMLElement interface of the element the attribute is set on. The HTMLElement.dataset property gives access to them.
Reference
I am having a aspx page,in which there is a Select box control
<select name="selViewPerPage" id="selViewPerPage" style="width:30px">
In order to bring a particular style in all browsers, i am replacing this html control with dynamic select box using "selectBox.js" . Now the problem is , i am having two dropdowns in the page ,during runtime they are generated with same class name without any ids.So while trying to position the controls using css,the both drop downs takes the same position.
So i am not sure ,how to handle this situation .Please let me know,if you need more information.
Thnks
Try using a pseudo-selector to get just a specific item, such as the first, last, or nth item. See :eq() or :first() or :last() for example: http://api.jquery.com/category/selectors/. Using one of those sorts of selectors, you can get just the element you want to modify and apply styles to it individually. Ex.
$('ul').first()
or
$('ul:last')
or
$('ul').eq(1)
Or some other variant of these.
If you have multiple instances of items with the same class, use the .eq() selector.
$('.someSelect').eq(0) <-- first instance
$('.someSelect').eq(1) <-- second instance
What I am trying to achieve is a second dropdown list to be populated with values based on the selection of the first dropdown list.
I've got it to work using the following:
http://jsfiddle.net/ydPfH/6/
The problem is that an external plug in that I am using to display images in a drop down list somehow stops this code from working properly.
The code that initalises this plug-in is $("body select").msDropDown(); and what I have below the simple search form that uses this plug-in is a jquery expandable div so you click Advanced Search to expand the form with the dynamic dropdowns.
<a href="#" rel="toggle[advancedsearch]" data-openimage="images/collapse.png" data-
closedimage="images/expand.png">Advanced Search<img id="expand"
src="images/collapse.png"/> </a>
<div id="advancedsearch">
<p>Document Properties:</p>
<form>
<select id="tags" name="tags" class="tags">
etc....
What I'm hoping for is some kind of onclick or something even easier to call to another JS method to somehow remove the $("body select").msDropDown(); initialisation or to even initialise something silly that in turn removes it.
Full source of the page can be seen here if it helps: http://jsfiddle.net/pQ9LT/
Thanks,
Martin
If I'm getting this right, here is the answer:
You should add class attributes to the <select> elements that are going to be using your msDropDown plugin. Then initialize the plugin like this $('select.yourClass').msDropDown();
where yourClass is the class name you assigned these <select> elements.
The body part in your selector is superflous.
This way, jQuery will only apply the plugin to the <select> elements "marked" with you class name and not all of them so you can use the other "normal" <select> elements without interference.
Hope I helped you out.
I'm not completely clear on what your overall requirements are and what may or may not be acceptable so where are a few thoughts that I have.
Give the select elements you do not want styled as image combo boxes a class or an id. Then use the :not() selector in combination with your msDropdown initialization
$("body select:not('.nostyle')").msDropDown(); //using the class 'nostyle' to filter out the elements that should get the image combobox
Use a more specific selector in the initialization call; this is kinda the opposite of the above
$("body select.classOfSelectsTobeStyled").msDropDown(); //using the class 'classOfSelectsTobeStyled' on elements that should get the image combobox