I have an issue with utext in thymeleaf. I want to show a table as a hover.
This is my code
<td class="CellWithHtmlContent" th:title="${event.note}">
<span class="CellContent" ></span>
<span th:if="${event.note != null}"
th:utext="${!#strings.startsWith(event.note,'<') ? #strings.abbreviate(event.note, 60) : 'More'}"></span>
</td>
I have used th:title to show the table when hovering. But it just show the html code. Using th:utext, can show the table properly. but It isn't act as a hover. Is there any way to use th:utext inside the th:title?
Like this --> th:title = utext(${event.note})
Thymeleaf does not support this. It is not possible to have a browser render HTML in a title attribute. See Is it possible to add html inside a title attribute?
You will need to use something like https://atomiks.github.io/tippyjs/
Add this JavaScript snippet to your page:
<script>
document.addEventListener('DOMContentLoaded', function (event) {
tippy('.tooltip', {
content(reference) {
const id = reference.getAttribute('data-tooltipid');
const template = document.getElementById(id);
return template.innerHTML;
},
allowHTML: true
});
});
</script>
Now, add something like this:
<td class="CellWithHtmlContent" th:title="${event.note}">
<span class="CellContent" ></span>
<span th:if="${event.note != null}"
th:attr="data-tooltipid=${'cell-tooltip-'+event.id}"></span>
</td>
(I assumed event has an id. You will need something to make the tooltip reference unique for each tooltip on the current page).
Now, also have some hidden HTML on the page that will be loaded into the tooltip by the Tippy library:
<div th:id="${'cell-tooltip-'+event.id}" class="hidden">
<span th:if="${event.note != null}"
th:utext="${!#strings.startsWith(event.note,'<') ? #strings.abbreviate(event.note, 60) : 'More'}"></span>
</div>
It is important that the id of the hidden HTML matches with the data-tooltipid for the tooltip to work.
Related
I'm trying to use expand-collapse feature of bootstrap 4 and was encountering a weird issue with the use of *ngIf for expansion and collapse.
Whenever I try to use *ngIf as follows, the jquery doesn't work but works when *ngIf is deleted.
HTML:
<div class="collapse-group">
<div class="row">
<div class="col-md-7" id="row">
<div id="link_text_div" *ngIf="this.collapseExpandArrowFlag==true">
<span id="collapse_all" class="close-button" (click)="arrowFunc($event)" style="cursor: pointer;" >
Collapse all
</span>
</div>
<div id="link_text_div" *ngIf="this.collapseExpandArrowFlag==false">
<span id="expand_all" class="open-button" (click)="arrowFunc($event)" style="cursor: pointer;"
>
Expand all
</span>
</div>
</div>
</div>
</div>
.Ts:
collapseExpandArrowFlag = true;
arrowFunc(event) {
if(event.srcElement.id === "collapse_all") { //On-Click Collapse Logic
this.collapseExpandArrowFlag = false;
$(".close-button").on("click", function() {
$(this).closest('.collapse-group').find('.multi-collapse').collapse('hide');
});
}
if(event.srcElement.id === "expand_all") {
this.collapseExpandArrowFlag = true;
$(".open-button").on("click", function() {
$(this).closest('.collapse-group').find('.multi-collapse').collapse('show');
});
}
Try to remove "this" in the ngIf like this:
*ngIf="collapseExpandArrowFlag==true"
Please remove the 'this.' from the *ngIf and just write
*ngIf="collapseExpandArrowFlag"
If this not working , try to change *ngIf to
[hidden]="collapseExpandArrowFlag"
and
[hidden]="!collapseExpandArrowFlag"
This will add the element and the event on the dom on load time. and will keep it there (with a display : none property in css).
Plus take into consideration how you need to work with external library code like JQuery.
See references:
Use jQuery script with Angular 6 CLI project
Change you ts file as follows
collapseExpandArrowFlag = true;
arrowFunc(event) {
if(event.srcElement.id === "collapse_all") { //On-Click Collapse Logic
this.collapseExpandArrowFlag = false;
$(this).closest('.collapse-group').find('.multi-collapse').collapse('hide');
}
if(event.srcElement.id === "expand_all") {
this.collapseExpandArrowFlag = true;
$(this).closest('.collapse-group').find('.multi-collapse').collapse('show');
}
What's happening here is, when you click the button, inside ts code,
this.collapseExpandArrowFlag = false;
is called, and in the template the close-button is removed.
But in the very next line of ts code,
$(".close-button")
is called, But in this state that element is removed from the DOM
And make sure you've removed this. from *ngIf statements
I have a scenario where I have to give action link to both icon and text. How can I do this with #html.Actionlink. I tried to add icon html code inside actionlink as text but it didnt work. How can we handle these cases with out using normal anchor tag?
<div>
<span class="glyphicon glyphicon-hdd"></span>
</div>
<div>
#Html.ActionLink("Request", "Request", "MyRequest")
</div>
As #Stephen in the comments mentioned, you can't use ActionLink() and include an icon. You're going to have to use an anchor. Your code in this format would look as follows:
<a href="#Url.Action("Request", "MyRequest")">
<span class="glyphicon glyphicon-hdd"></span>
<span>Request</span>
</a>
You can use the javascript code, like :
#Html.ActionLink("Request", "Request", "MyRequest", new { #class = "btn-primary", id = "btn-actionlink-export" })
<script type="text/javascript">
$(document).ready(function () {
$('#btn-actionlink-export').append('<span class="icon-file-excel position-right"></span>');
});
</script>
I have a page with a set of jQuery accordions built from an MVC foreach statement.
Before each accordion, I would like to add some text in a <p> tag. Whatever I have tried, the jQuery styling has added classes and styles to my tag.
Is there a simple way to add a <p> tag and say that I want it the same as the other <p> tags on the non jQuery page? Almost like an inline !important setting.
EDIT
Code to build accordions:
<section id="accordions" aria-label="accordion-expand\collapse" class="col-md-12">
#{
foreach (var accordion in Model.Content.Children.Where(f => f.DocumentTypeAlias.Equals("Accordion", StringComparison.CurrentCultureIgnoreCase)))
{
var isInScheme = Model.User != null ? Model.User.IsInScheme(accordion.GetPropertyValue<String>("schemeTypes")) : false;
var isMemberStatus = Model.User != null ? Model.User.IsMemberStatusType(accordion.GetPropertyValue<String>("memberStatusTypes")) : false;
if ((!accordion.HasValue("schemeTypes") && !accordion.HasValue("memberStatusTypes")) || (isInScheme && isMemberStatus))
{
if (accordion.GetPropertyValue<String>("accordionText") != "" & accordion.GetPropertyValue<String>("accordionText") != null)
{
<p>accordion.GetPropertyValue<String>("accordionText")</p>
}
<h3 class="clearfix" id="#accordion.Id">
<span class="title">#(accordion.GetPropertyValue<String>("accordionHeader"))</span>
</h3>
<article class="clearfix">
#(Html.Raw(accordion.GetPropertyValue<String>("accordionContent")))
</article>
}
}
}
</section>
where the accordionText is being inserted, jQuery is adding the classes to it.
If I understood correctly, the problem is your jQuery CSS selector.
You may have something like this:
$("p").addClass("class");
That is why jQuery is matching all your <p> tags, even the ones you do not want it to.
What you could do is change your tag selector to a class selector, then use this class in the descendant <p> elements of the accordion.
Option 1:
Change this:
<p>accordion.GetPropertyValue<String>("accordionText")</p>
To this:
<p class="accordion-text">accordion.GetPropertyValue<String>("accordionText")</p>
And this:
$("p").addClass("class");
To this:
$(".accordion-text").addClass("class");
Option 2:
$("#accordions p").addClass("class");
I'm new to Angular but I'm trying to implement a textbox that allows users to enter in links. I only want to support links, and otherwise I want to block all html from being presented as such. I could theoretically use something other than a textarea, but my requirements are that it must be bound to a variable in my scope (right now with ng-model) and I cannot accept html tags other than '< a >'
Here is my example plnkr
In the example, I would like the second seeded item to display as a link, blue and underlined. However, the third item should display as it is currently shown (without interpreting it as html).
HTML:
<textarea maxlength="160" ng-model="val.text"></textarea>
<div class="btn" ng-click="submit()">Submit</div>
<br><br>
<div ng-repeat="item in items">
{{display(item)}}
</div>
JS:
$scope.submit = function() {
if (!$scope.val.text) return
$scope.items.push($scope.val.text);
}
$scope.display = function(txt) {
return txt;
// something here? if txt contains <a> and </a> indicate
// that we should display as html
}
I have this html/smarty code for a radio button. I would like to extend the area for the selection of the radio button so that the user can more easily select it on this page?
The classic trick of using label is insufficient here. All the actions performed when clicking the button must be performed, see the onchange parameters. I need to make a clickable zone including at least the whole table that contains this line, or even better: a zone that also contains the image above each radio button.
Is that possible in html, css, jquery?
Thanks
<tr>
<td valign="top">
<input value="{$id_attribute|intval}" class="{$groupName}" type="radio" name="{$groupName}" id="group_{$id_attribute_group|intval}" onchange="javascript:findCombination({$groupName});changeCombinationPrice();{if $groupName=='group_1'}getCheckedValue(document.forms['buy_block_form'].elements['group_1']);scaleImage('{$group_attribute|escape:'htmlall':'UTF-8'}','{$cover.id_image}.jpg');{else if $groupName=='group_2'}changeImage('{$group_attribute|escape:'htmlall':'UTF-8'}','{$cover.id_image}',{$id_attribute|intval}); {/if}" {if ($groupName=='group_1' and $countGroup1==1) } checked {/if} />
</td>
{assign var="hrup" value=$group_attribute|escape:'htmlall':'UTF-8'|lower}
{if $feact==$hrup}
<td width="17" valign="top">
<script language="javascript" >
Tooltips('{$feact},{$hrup}');
</script>
<div class="tooltip">
<div class="toolimg"><img src="/pixelart/img/layout/corazon.jpg">
</div>
<div class="tooldescrip">{l s="Finition recommandée par l'artiste"}
</div>
</div>
{/if}
</td>
<td>
<div class="imputgroup_{$id_attribute|intval}">{$group_attribute|escape:'htmlall':'UTF-8'}
</div>
</td>
</tr>
<tr>
You need to wrap the clickable content in another tag (A is appropriate) and hook up the event handler to that tag. You'll also have to switch the radio buttons in JavaScript accordingly.
wrapped the area with a a tag:
<a href="Javascript:void()" id="radioClickAreaid{$id_attribute|intval}" onclick="radioClickArea(document.forms['buy_block_form'].elements['{$groupName}'], '{$id_attribute|intval}');javascript:findCombination({$groupName});changeCombinationPrice();{if $groupName=='group_1'}getCheckedValue(document.forms['buy_block_form'].elements['group_1']);scaleImage('{$group_attribute|escape:'htmlall':'UTF-8'}','{$cover.id_image}.jpg');{else if $groupName=='group_2'}changeImage('{$group_attribute|escape:'htmlall':'UTF-8'}','{$cover.id_image}',{$id_attribute|intval}); {/if}">
that has the same onclick parameters as the onchange from the radio button (not very elegant though!), and that calls a javascript function:
function radioClickArea(radioObj, id_attribute) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == id_attribute.toString());
return;
}
for(var i = 0; i < radioLength; i++) {
radioObj[i].checked = false;
if(radioObj[i].value == id_attribute.toString()) {
radioObj[i].checked = true;
}
}
return false; // so that the link goes nowhere
}
The radio button gets selected OK.
Is there a way not to repeat the onchange/onclick parameters?
Or like suggested here - use tag surrounding your radiobutton or checkbox:
How can I make an HTML radiobutton with a big target area?