hiding the slider input box in jquery - jquery-mobile

I am using jquery Mobile 1.0.
I have this html code.
<label for="slider" class="ui-hidden-accessible">
Input slider:
</label>
<input type="range" name="slider" id="#(Model.QuestionNo)_slider" value="25" min="0" max="100" />
Its rendering like this:
But I want to remove the red marked part. I want to show only slider part.
How can this be done?

If you just want to get rid of the up/down arrows, you can wrap the input in an element with a specified width/height and overflow : hidden:
$(".ui-slider-input").wrap($('<div />').css({
position : 'relative',
display : 'inline-block',
height : '36px',
width : '45px',
overflow : 'hidden'
}));
Or as Frederic Hamidi stated, you can just hide the element all together and only a slider will be visible.
Here is a demo of the above code: http://jsfiddle.net/EWQ6n/1/
Also you can hide the input element with CSS (which is nice because you don't have to time the execution of the CSS like you do with JS):
.ui-slider-input {
display : none !important;
}
Here is a demo using CSS: http://jsfiddle.net/EWQ6n/2/
Update
Instead of using the !important keyword, you can also make a more specific CSS rule so it is used over the jQuery Mobile classes. An example would be:
.ui-mobile .ui-page .ui-slider-input,
.ui-mobile .ui-dialog .ui-slider-input {
display : none;
}

input.ui-slider-input {
display: none;
}

You could hide the input control manually:
$("#yourPage").live("pageinit", function() {
$(".ui-slider-input").hide();
});

If you only want to get rid of the up/down arrow use type="text" data-type="range"
<input type="text" data-type="range" name="slider" id="#(Model.QuestionNo)_slider" value="25" min="0" max="100" />

I wanted to do this too, but I also wanted the space to go away. I accomplished this this way (I'm using a range slider):
<div data-role="rangeslider" data-mini="true" class="no-number">
<input type="range" name="Morn" id="Morn" data-mini="true" value="720" min="0" max="1439">
<input type="range" name="Night" id="Night" data-mini="true" value="10800" min="0" max="1439">
</div>
Notice I added the .no-number to the div.
Then in css:
/* Used to remove the number next to the slider.*/
.no-number .ui-slider-input
{
display : none;
width: 0px;
}
/* Used to remove the space where the number was. */
.no-number .ui-rangeslider-sliders
{
margin: 0 5px; !important
}
I'm doing this all as part of a bigger issue, which is that I'm trying to use a range slider for time instead of numbers, so I replaced those elements with a heading I can change with a function to display the time.
This may not be the perfect choice, but I didn't see where to get the space back anywhere, so I thought I would post it here.

When you do it using CSS approach, you may break the input filed of other. So adding the class="ui-hidden-accessible" class to the input to hide it.
Remove this class="ui-hidden-accessible" from label.
Your approach is correct. But you need to add class="ui-hidden-accessible" to input not on the label.
Your code should be like this:
<label for="slider">Input slider:</label>
<input type="range" name="slider" id="#(Model.QuestionNo)_slider"
value="25" min="0" max="100" class="ui-hidden-accessible"/>
Check this SAMPLE DEMO

<input type="range" name="slider_sodio" id="slider_sodio" value="0" min="0" max="3" step="1" class="ui-hidden-accessible" />
but look that anoy offset
.ui-slider-track {
margin: 0 15px 0 68px; ----> change to 10
}

You Can Remove Input Slider As Below :
input.ui-slider-input {
display: none;
width: 0;
}
.ui-slider-track {
margin: 0 15px 0 15px !important;
}

Related

Angular Material Dialog with Google Places Autocomplete dropdown positioning

I have a web page that uses the Angular framework and therefore the Materials UI library. I have a dialog with a form that uses the Google Places Autocomplete functionality, but the positioning of it stays constant when scrolling through the dialog. Without the dialog, the autocomplete positioning works as I would like and stays directly beneath the input. No styling on the .pac-container has been done for the positioning. The dialog and non-dialog have the same code and styling. Thank you in advance! (Mind the ugliness, it is all testing right now)
google.maps.places.Autocomplete position offset inside angular material Dialog is the exact issue I am having (I think), but I do not know what is meant by "My solution was to remove the top style and then restore it."
Initial position of autocomplete in the dialog
Autocomplete position when scrolling through the dialog
Initial position of autocomplete outside dialog
Autocomplete position when scrolling outside dialog
Non-Dialog TS:
export class AddressTestComponent implements OnInit, AfterViewInit {
#ViewChild("addressLine1") addressField1: ElementRef;
#ViewChild("addressLine2") addressField2: ElementRef;
#ViewChild(MatAutocompleteTrigger, {static: false}) trigger: MatAutocompleteTrigger;
addressForm: UntypedFormGroup;
googleAutocomplete: google.maps.places.Autocomplete;
constructor(private formBuilder: UntypedFormBuilder) { }
ngOnInit(): void {
this.addressForm = this.formBuilder.group(
{
addressLine1: ['', Validators.required],
addressLine2: [''],
city: ['', Validators.required],
state: ['', Validators.required],
zipCode: ['', Validators.required],
country: ['', Validators.required],
}
);
}
ngAfterViewInit(): void {
this.googleAutocomplete = new google.maps.places.Autocomplete(this.addressField1.nativeElement as HTMLInputElement, {
componentRestrictions: { country: ["us"] },
fields: ["address_components"],
types: ["address"]
});
this.addressField1.nativeElement.focus();
this.googleAutocomplete.addListener("place_changed", () => this.autocomplete(this.googleAutocomplete.getPlace()) );
}
}
Non-Dialog HTML:
<div>
<div class="dialog-header">
<h2>Add a New Address</h2>
<h2 class="header-closer" (click)="onClose()" >X</h2>
</div>
<form [formGroup]="addressForm" (ngSubmit)="onSubmitNewAddress()" class="address-form">
<div class="address-wrapper">
<mat-form-field (keydown.escape)="$event.stopPropagation()"
appearance="fill">
<mat-label>Address Line 1</mat-label>
<input matInput #addressLine1 formControlName="addressLine1" required>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>Address Line 2 (Optional)</mat-label>
<input matInput #addressLine2 formControlName="addressLine2">
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>City</mat-label>
<input matInput formControlName="city" required>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>State</mat-label>
<input matInput formControlName="state" required>
</mat-form-field>
<mat-form-field appearance="fill" style="margin-bottom: 10px;">
<mat-label>Zip Code</mat-label>
<mat-hint align="end">{{ zipcode.value.length }} / 5</mat-hint>
<input matInput #zipcode type="tel" [maxLength]="5" formControlName="zipCode" required>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>Country</mat-label>
<input matInput formControlName="country" required>
</mat-form-field>
</div>
<div class="form-buttons">
<button mat-raised-button (click)="onClose()">Cancel</button>
<button mat-raised-button color="primary" type="submit" [disabled]="this.addressForm.invalid">Use This Address</button>
</div>
</form>
</div>
Non-Dialog SCSS:
.dialog-header {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 5px;
}
#map {
height: 100%;
}
.address-form {
padding-bottom: 2000px; // for scrolling test
}
.header-closer {
cursor: pointer;
color: red;
margin-top: 30px;
}
.address-wrapper {
display: flex;
flex-wrap: wrap;
mat-form-field {
margin: 0 15px;
flex: 1;
}
}
.form-buttons {
button {
margin: 0 5px;
}
button:hover {
background-color: #771f1f;
}
}
I have tried the autocomplete without a Material Dialog and it works just as intended and how I would like it to work. I am just trying to replicate that while scrolling through the dialog as well. To fix the issue, I tried to change the position styling of .pac-container but was unsuccessful.
EDIT: I figured out what the other stackoverflow link was talking about. Is there a way the autocomplete styling can be tied to the actual input element rather than the html tag?

Select2 jQuery plugin - "multiple" - remove gray [ ] around search box - only happens in Safari

Select2 4.0 jQuery plugin
In (Mac) Chrome or Firefox, the multiple select box looks fine with default, selected values:
but in (Mac) Safari it looks like below (light gray bracket around what is the <input> element for typing in a search term.)
What is the preferred way (i.e. select2 option or select2 css) to get rid of this visual artifact: [] ?
The HTML element generated by select2 is this:
<span class="select2 select2-container select2-container--default select2-container--below" dir="ltr" style="width: 110px;">
<span class="selection">
<span class="select2-selection select2-selection--multiple" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0">
<ul class="select2-selection__rendered">
<li class="select2-selection__choice" title="Text">
<li class="select2-selection__choice" title="Video">
<li class="select2-search select2-search--inline">
<input class="select2-search__field" type="search" tabindex="-1" autocomplete="off"
autocorrect="off" autocapitalize="off" placeholder=""
spellcheck="false" role="textbox" style="width: 0.75em;"/>
</li>
</ul>
</span>
</span>
I tried both of the below (now commented out) select2 options to no effect:
$j(".select2").select2({ // we're using the Select2 plugin
// minimumResultsForSearch: Infinity // has no effect on Safari
// placeholder: null // attempt two - no effect
});
The only select2 class styles overridden are:
<style type="text/css">
.select2 { /* select2 honors width CSS property */
font-size: xx-small;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice { /* The results container with MSP-chosen values */
margin-left: .2em;
padding: 0px 2px;
}
.select2-results__option { /* The list of available MSP choices */
font-size: xx-small;
margin-left: .2em;
padding: 0px 4px;
}
</style>
The answer comes courtesy of select2 gitHub Issues - Select box not displayed properly in safari #3459
Specifically, this line of css:
.select2-search__field {
-webkit-appearance: textfield;
}
Per Kevin Brown, added to 4.01 milestone

Prevent checkbox being checked after taphold

I've been trying for days now, but it won't work. I have a controlgroup containing some checkboxes, which are being bound with knockout.js:
<div data-role="content">
<div data-role="fieldcontain" data-bind="with:selectedList, jqmRefreshList:selectedList">
<fieldset data-role="controlgroup" data-bind="foreach: { data: items }" data-inset="true" data-filter="true" data-mini="true">
<input type="checkbox" data-bind="attr: {id:guid}, checked:isChecked" />
<label data-bind="text:value, attr: {for:guid}"></label>
</fieldset>
</div>
</div>
I'm using a "taphold" event, on which I want to open a popup:
$(document).on('taphold', '.ui-checkbox', function (event) {
$('#listitem-page #add-listitem-popup').popup('open', { transition: 'pop' });
});
The popup opens normally, but the big problem is that the checkbox is being checked as well. The checkbox should only be checked on a "tap" or "vclick", which is the default behaviour and seems to work fine. The problem is that when i taphold (long touch), the popup is opened, and at the moment I release my finger from the screen, the vclick is generated and the checkbox is checked.
I tried several things (on the right location in the document):
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
$.event.special.tap.emitTapOnTaphold = false;
.ui-checkbox {
-webkit-touch-callout: none !important;
}
.ui-mobile {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
in the vclick eventhandler (and the taphold eventhandler), but there seems no way to cancel the vclick from happening after I release my finger from the screen (taphold). Does anyone have suggestions? Thank you!
PS, the problem is on an Android device...

How can I show a "loader" during knockout.js initialization?

I have a single-page web-app built with knockout.js and jQuery Mobile.
The view-model initialization (i.e. the ko.applyBindings() function) takes about 7-8 seconds. During this time, the page shows blank.
$(document).ready(function () {
ko.applyBindings(viewModel);
})
Is there a way to show the JQM loader in the meantime, or to show a kind of "splash screen", to give to the user a feedback that the "page is loading"?
Note that it seems to me that the solution proposed by #Jeroen is also good together with the default page transitions of jQuery Mobile, at least as I can see in this jsfiddle.
To be honest, the tip proposed by #Omar seems to me to have better integration with JQM, and I will try in the future to combine both answers, with a writeable computed observable to switch the JQM loader on/off.
Keep it simple! Show a loading overlay in your html by default, but use a visible: false binding of some kind. That way when the applyBindings call is done the UI will hide the overlay.
For example, suppose this view:
<div id="main">
<div id="loading-overlay" data-bind="visible: loading"></div>
Some content<br />
Some content
</div>
And suppose this view model:
vm = { loading: ko.observable(true) };
Then calling this:
ko.applyBindings(vm);
If for whatever reason it takes 7 secs to load, the loading-overlay will be shown until the UI is updated.
This approach is great if you have a client side DAL or some single point where you run Ajax calls, because you can follow this pattern:
vm.loading(true)
Ajax call with callbacks for success and failure
On callback do vm.loading(false)
Knockout will handle the overlay visibility for you.
See this fiddle for a demo, or check out this Stack Snippet:
vm = { loading: ko.observable(true) };
ko.applyBindings(vm);
// Mock long loading time:
window.setTimeout(function() {
vm.loading(false);
}, 5000);
html { height: 100%; }
body {
position: relative;
height: 100%;
width: 100%;
}
#loading-overlay {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: url('http://img.cdn.tl/loading51.gif') white no-repeat center;
opacity: 0.75;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script>
<div id="main">
<div id="loading-overlay" data-bind="visible: loading"></div>
Some content<br />
Some content<br />
Some content<br />
Some content<br />
Some content<br />
<input type='text' value='cant edit me until overlay is gone' /><br />
<button>can't press me until overlay's gone!</button><br />
Some content<br />
Some content<br />
Some content
</div>

MVC extra hidden checkbox in forms breaking custom css checkbox

I am trying to customize the look and feel of the checkboxes in my ASP.NET MVC site, using a technique like the one detailed here: http://cssdeck.com/labs/css-checkbox-styles
They work great except when placed in a form. When using the #Html.CheckBoxFor() method, MVC adds an extra hidden checkbox, apparently to make sure that a value is submitted to the form POST when the checkbox is not checked: asp.net mvc: why is Html.CheckBox generating an additional hidden input
When the extra hidden checkbox is on the form, my custom checkbox does not work. I click it but it does not toggle between the states. If I remove the extra hidden checkbox, then it works, but I guess I'll run into problems submitting the POST.
Here is the final html:
<div class="kbcheckbox">
<input checked="checked" data-val="true" data-val-required="The Approved field is required." id="UserEdit_IsApproved" name="UserEdit.IsApproved" type="checkbox" value="true">
<input name="UserEdit.IsApproved" type="hidden" value="false">
<label for="UserEdit_IsApproved"></label></div>
</div>
And here is the css I am using (uses scss)
.kbcheckbox {
width: $checkbox_size;
height: $checkbox_size;
position: relative;
input[type="checkbox"]{
visibility: hidden;
}
label {
cursor: pointer;
position: absolute;
width: $checkbox_size;
height: $checkbox_size;
top: 0;
left: 0;
border-radius: $control_corner_radius;
border: 1px solid $control_border_color;
/*#include box-shadow(1px, 1px, 1px, 0, $control_border_color, inset);*/
/*#include box-shadow(0px, 1px, 0px, $control_background);*/
background: white;
}
label:after {
opacity: 0;
content: '';
position: absolute;
width: $checkbox_size * 0.62;
height: $checkbox_size * 0.25;
background: transparent;
top: $checkbox_size * 0.2;
left: $checkbox_size * 0.1;
border: 3px solid black;
border-top: none;
border-right: none;
#include transform(rotate(-45deg));
}
label:hover {
background: darken($control_background, 10%);
}
input[type=checkbox]:checked + label:after {
opacity: 1;
}
}
Any ideas?
Use the following in your css. You want all your elements to be modified.
input[type = checkbox]:checked ~ label:after {
opacity: 1;
}
Here is the fiddle
You can solve this problem by wiring up an event when the checkbox is checked to change the value on an MVC hidden field instead, essentially doing the same thing without using the MVC helper
#Html.HiddenFor(model => model.UserEdit.IsApproved, new { #id = "chkIsApproved" })
Here is your HTML then
<div class="kbcheckbox">
<input checked="checked" data-val="true" data-val-required="The Approved field is required." id="UserEdit_IsApproved" name="UserEdit.IsApproved" type="checkbox" value="true">
<label for="UserEdit_IsApproved"></label></div>
</div>
Then just use some jQuery to wire up the checked property with the hidden field
$('#UserEdit_IsApproved').change(function() {
$('#chkIsApproved').val($(this).is(':checked'));
});
As long as the MVC hidden field is somewhere, the value will be posted to the controller. It is a little extra work, but it should get you the result you want.
My solution is somewhat hacky but you can just move all hidden fields before the checkboxes using jQuery
$(".checkbox > input[type=checkbox]").each(function( key, checkbox ) {
var hidden = $(checkbox).siblings("input[type=hidden]");
$(hidden).insertBefore($(checkbox));
});

Resources