Bootstrap datetimepicker in a div visible on mouseover - css

I have an issue with the datetimepicker from bootstrap.
I have a table containing a list of items, and on each column, I have an input to make some search on each field from the items.
I have a field "creationDate" and I want to be able to search a date between two dates, so to take less space, i have an icon for this field which shows a div on ng-mouseenter which contains the 2 inputs with datetimepicker.
The code of this part is like this :
<td>
<img src="/assets/css/images/unroll-icon.png" ng-mouseenter="showSelectCreationDate()" />
<div class="selectCreationDate" id="selectCreationDate" ng-mouseleave="hideSelectCreationDate()">
Date min. :
<input type='text' data-date-format="DD/MM/YYYY" class="form-control" id='inputCreationDateMin' />
<br />Date max. :
<input type='text' data-date-format="DD/MM/YYYY" class="form-control" id='inputCreationDateMax' />
<script type="application/javascript">
$(function () {
$('#inputCreationDateMin').datetimepicker({
pickTime: false
});
});
$(function () {
$('#inputCreationDateMax').datetimepicker({
pickTime: false
});
});
</script>
</div>
</td>
The problem is that when I move my mouse in the datetimepicker popup, it is considered as a mouseleave from the div, so it disappears and I can't select the date.

Ok so the problem is that when you mouse over a id/class it hides your popup- try this:
$(document).on("mouseover", "#nameOfyourField", function (e) {
//Do whatever you want to do
});
Now if you click somewhere in the body of your web-page the popup will go away:
$(document).on("click", "body", function () {
$("#nameOfyourField").hide();
});
I hope this is what you're looking for:

Related

Angular 6: ngx-translate not working with data-title attribute for tooltips

I'm developing an Angular 6 app which uses ngx-translate for localization and I'm also using Bootstrap 4 tooltips and the problem I'm facing is I'm not being able use localization keeping Bootstrap tooltip style.
Without localization I would use an input this way:
<input type="text" class="form-control text-truncate" id="position"
placeholder="position" data-title="position" />
And this will show a very nice Bootstrap tooltip as it can be seen below:
With ngx-translate localization I would use an input this way:
<input type="text" data-toggle="tooltip" class="form-control tooltipped text-truncate" id="position"
[attr.placeholder]="'wfrh_vacancyform_position' | translate"
[attr.data-title]="'wfrh_vacancyform_position' | translate" />
and the problem here is data-title attribute. "data-title" attribute is used to display the tooltip but I guess ngx-translate doesn't recognize it (maybe?).
Placeholder is working fine this way (the text is translated and shown correctly) but tooltip won't show.
I've also tried this way:
<input type="text" data-toggle="tooltip" class="form-control tooltipped text-truncate" id="position"
placeholder="{{'wfrh_vacancyform_position' | translate}}"
data-title="{{'wfrh_vacancyform_position' | translate}}" />
which is also not working (it only works for placeholder) so I'm stuck.
If I do:
<input type="text" data-toggle="tooltip" class="form-control tooltipped text-truncate" id="position"
[attr.placeholder]="'wfrh_vacancyform_position' | translate"
[attr.title]="'wfrh_vacancyform_position' | translate" />
then the tooltip shows but with no style as it can be seen in the next image:
And this is the way I create the tooltips in code (in ngOnInit):
ngOnInit() {
setTooltip()
}
setTooltip() {
$('.tooltipped').tooltip({
placement: 'auto',
trigger: 'focus',
template: '<div class="tooltip" role="tooltip"><div class="arrow"></div><div class="tooltip-inner bg-dark text-light"></div></div>'
});
$('.tooltipped').bind("mouseover", function () {
var _this = $(this);
_this.tooltip("show");
});
$('.tooltipped').bind("mouseout", function () {
var _this = $(this);
_this.tooltip("hide");
});
$('.tooltipped').bind("keyup", function () {
var _this = $(this);
_this.tooltip("hide");
});
}
Well I'm stuck. I need to be able to display this nice styled tooltip with translation. Any help / ideas?
Thanks.
Ok, after long time investigating I was able to find a solution and I'll post it here in case it helps anyone else.
The problem is I was setting tooltip in onInit (which is fired only once when the component is created) and wasn't setting any tooltip text, just leaving it to pickup the one set with:
[attr.data-title]="'text_to_translate_key' | translate"
(the initial text translation) and after changing language tooltip was not refreshing (the text was static with the initial value) but you can use a function with the tooltip "title" property this way:
$('.tooltipped').tooltip({
placement: 'auto',
trigger: 'focus',
template: '<div class="tooltip" role="tooltip"><div class="arrow"></div><div class="tooltip-inner bg-dark text-light"></div></div>',
title: this.setTitle
});
setTitle() {
return $(this).attr("placeholder");
}
and this function (which has current object reference -this- as an implicit input parameter) acts as a binding which updates the title property continuosly so when placeholder text changes (placeholder does not need to be refreshed after language changes and that's why it works) the tooltip "title" property will be updated and as a consequence tooltip text will change and user will see updated text.
"The end" :)

Add asterisk to the required field label

I have a (unchangable) form structure like this:
<div class="form-group">
<div class="col-sm-3 control-label">
<label for="frm-registrationForm-form-surname">Surname:</label>
</div>
<div class="col-sm-9">
<input class="form-control text" id="registration-form-surname" type="text" name="surname" required>
</div>
</div>
Is there possible to add the asterisk * sign next to all the labels relying to the inputs with "required" attribute using the CSS? I did not find any option to link the input with the label in CSS even in the same form group.
Thanks.
Using jQuery.
First solution. If .form-group has only one input and label elements.
$(document).ready(function () {
$('input[required]').parents('.form-group').find('label').append('*');
});
Second solution. Working only of your label for and input id attributes the same
$(document).ready(function () {
$("input[required]").each(function(index) {
var id = $(this).attr('id');
$('label[for="'+id+'"]').append('*');
});
});
I would recommend you to use the second solution.
You can use jQuery to implement this functionality. Inside document.ready function,
var str ='*';
$(".control-label").append(str);
Entire script would be
$(document).ready(function () {
var str ='*';
$(".control-label").append(str);
});

How to find the default tab index of controls?

I want to find the default tab index of the form.
I have not given but still all the control has the tab index. I want to find that default tab index through the j query. How can i find that?
Jquery and tab-index
The way tabindexing works is that it goes trough your html markup and looks for tabable elements.
So say you have this code:
<form>
<label>Name:</label>
<input type="text" />
<br>
<input type="submit" />
</form>
The text input will be tabbed first, and then the submit input.
Yes i know this how do it get the tabbing?
$(function() {
$firstinput = $("form").find("input")
console.log($firstinput.first()); //prints the first element thats an input.
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<label>Name:</label>
<input type="text" />
<br>
<input type="submit" />
</form>
The code above will only work if you only have input elemtns and add not trickery to the markup like hiding your elements etc.
In the code below im using the jquery UI :focusable selector.
With this you should get the first tabbable element in your form
//:focus selector from jquery UI
$.extend($.expr[':'], {
focusable: function(element) {
var nodeName = element.nodeName.toLowerCase(),
tabIndex = $.attr(element, 'tabindex');
return (/input|select|textarea|button|object/.test(nodeName) ? !element.disabled : 'a' == nodeName || 'area' == nodeName ? element.href || !isNaN(tabIndex) : !isNaN(tabIndex))
// the element and all of its ancestors must be visible
// the browser may report that the area is hidden
&& !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
}
});
//actual code
$(function() {
$form = $("form");
$first = $form.find(":focusable").first();
console.log($first);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<label tab-index="0">Name:</label>
<input type="text" />
<br>
<input type="submit" />
</form>
You can search for 'tabindex' attribute with jquery.
var tabindexVal = $('selector').attr('tabindex');

how to compare radio button values with textbox values in asp.net

i have four radio buttons and one text box..i have to check the selected radio button value equals to the textbox value.. anyone plz help me
if(radioButtonList.SelectedValue == textBox1.Text.Trim())
{
//your code goes here
}
textBox does not contain a Value property.
if (!string.IsNullOrEmpty(RadioButtonList1.SelectedValue) &&
RadioButtonList1.SelectedValue.Equals(TextBox1.Text, StringComparison.Ordinal))
{
//your code goes here
}
Well.You didn't clarify where you want to do this comparison i.e. ClientSide or ServerSide.If you want it server side you can prefer earlier posted answers otherwise for client side try this one using Jquery.
<div>
<input type='radio' name='rd' value='A'>
<input type='radio' name='rd' value='B'>
<input type='radio' name='rd' value='C'>
<br />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</div>
<script type="text/javascript" >
$(document).ready(function(){
$("input:radio[name='rd']").click(function(){
if($(this).is(":checked"))
{
if($.trim($(this).val()) == $.trim($("#txtName").val()))
alert("Yeah!I got matched value.");
else
alert("Oops!Not matched.");
}
});
});
</script>
Click on this link:
DEMO

jquery next button focus

To improve navigation on one of the pages I am tyring to set a focus on a next available(enabled) button when leaving last data entry field.
$('input[type=text], select, textarea').filter(':last').blur(function()
{
$('input[type=submit][type=button]:enabled:first').focus();
});
For some reason it only works when last data entry field is textbox. Something is wrong in the handler.
$(document).ready(function() {
$(':text,textarea,select').filter(':last').blur(function()
{
$(':button,submit:enabled:first').focus();
});
});
<body>
<textarea rows="3" /></textarea>
<select>
<option>1</option>
<option>2</option>
</select>
<input type="text" />
<input type="button" value="Something" />
</body>
Did the trick ... pretty much identical, so I don't know what's not working for you.
$('input').filter(':last').blur(function()
{
$('input:enabled:first').focus();
});
doesn't do the trick?
Assign the buttons a CSS class and try $('.ButtonClass:enabled:first').focus();

Resources