jQuery validate using custom div and css - css

I have a div that I want login error messages to go into:
<div id="loginMessage" class="blankBox"> </div>
When there are validation errors, I want the class of this div to be 'errorBox'. When there are no validation errors, I want the css to be 'blankBox'.
And I have the following jQuery validation:
<script>
$(function() {
$("#loginForm").validate({
rules: {
username: "required",
password: "required"
},
messages: {
username: "Please enter a username",
password: "Please enter a password",
},
errorLabelContainer: "#loginMessage",
wrapper: "li",
highlight: function(element) {
$(element).addClass('errorBox');
},
unhighlight: function(element) {
$(element).removeClass('errorBox');
},
});
});
</script>
Unfortunately, what's happening is that the errorBox css is being applied to the input fields. ?!? I cannot get this to work.
Any ideas?

Based on your comment from another answer:
"I want the css to be neutral until errors appear in it, and then reset
to neutral when errors leave it."
I have no idea what "neutral" means, but by default when all errors leave the container, the plugin makes the container "hidden". In other words, all that matters is the style of the container when it contains errors since it's only going to be seen when there are errors inside of it. Otherwise, it's simply hidden. To achieve this initial state, set the style to display: none;. You may also set your other properties for when it will be seen with errors. (refer to the jsFiddle example).
Despite the other answers, errorPlacement is no good in this scenario. It's only used for placing the individual messages. It has nothing to do with the messages inside the error container.
I also removed your highlight and unhighlight callback functions as those are fired off on a field-by-field basis and also would have nothing to do with your error container. (You've also broken their default functionality by over-riding them with your own functions.)
DEMO: http://jsfiddle.net/6dCB7/
jQuery:
$(document).ready(function () {
$('#loginForm').validate({ // initialize the plugin
errorLabelContainer: "#loginMessage",
wrapper: "li",
rules: {
// your rules
}
});
});
HTML:
<div id="loginMessage"></div>
<form id="loginForm">
....
</form>
CSS:
#loginMessage {
display: none;
/* also set the properties for when it displays with errors */
}

Related

Change CSS of a website with Chrome Extension - Some styles can't be changed

Now working.
I have a working Chrome Extension that will give me an injected stylesheet on the webpage I want but there are some styles I can not seem to overwrite.
For example, looking at the current Google home page I can inspect the empty area below and see there is no background color set. In the Styles section, if I click the "New Style Rule" button, (large plus sign) it gives me the correct (location?) for the rule ".o3j99.qarstb" when I copy the rule and add it as is to the CSS file it works. I get the injected stylesheet section added to the Styles and the color changes.
.o3j99.qarstb {
background-color: aqua;
}
I can also add this to the CSS and change the "About" and "Store" text size at the top left.
body, input, button {
font-size: 27px !important;
}
I'm trying to do something similar to another webpage but it's CSS or styles are more complex and it's hard to figure out if an injected stylesheet will even work. They do work when I make the change in place in the existing rule.
Here is the existing style rule:
.quixote .qx-grid .editor_grid tbody .input-group input {
width: 100% !important;
}
I added it to the styles.CSS file like this but it seems to be ignored as I can't find an injected stylesheet for it.
.quixote .qx-grid .editor_grid tbody .input-group input {
width: 900px !important;
}
This is the popup.js file. (Adding "allFrames: true" to the end of the insertCSS target got it working.)
$(document).ready(function() {
$('.reset').click(function() {
chrome.tabs.query({currentWindow: true, active: true}, function (tabs){
var activeTab = tabs[0];
/*alert("Button Reset");*/
chrome.scripting.removeCSS({
target: { tabId: activeTab.id },
files: ["styles.css"]
});
/*chrome.tabs.sendMessage(activeTab.id, {"buttonclicked": "reset"});*/
});
})
$('.format').click(function() {
chrome.tabs.query({currentWindow: true, active: true}, function (tabs){
var activeTab = tabs[0];
/*alert("Button Wider");*/
chrome.scripting.insertCSS({
target: { tabId: activeTab.id, allFrames: true },
files: ["styles.css"]
});
/*chrome.tabs.sendMessage(activeTab.id, {"buttonclicked": "wider"});*/
});
/*alert("Hello");*/
})
})
This is the content.js file. (Not sure why this was added but same code in the popup.js works even with all this commented out.)
/*var copy = $('body').clone()
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if( request.buttonclicked === "reset" ) {
$('body').html($(copy))
}
if( request.buttonclicked === "wider" ) {
chrome.scripting.insertCSS({
target: { tabId: tabId },
files: ["styles.css"]
});
}
})*/
This is the element the above rules are in.
<input class="form-control required" type="text" name="_obj__TIMESHEETITEMS_0_-_obj__PROJECTID" id="_obj__TIMESHEETITEMS_0_-_obj__PROJECTID" autocomplete="off" size="28" placeholder="Project" tabindex="0" style="min-width: 110px;">
It's a secure site so I can't post a link. Here is an example of the Table, I'd like to widen the first two columns.
Here is a pic of the inspect page, showing the element and two rules that I can manually change but can't with the CSS file.
What the "Stylus" extension adds and that works.

How to use [ngClass] in a *ngFor Angular component without a local index keeper?

I'm using the following markup to mark the clicked component as active.
<div *ngFor="let menu of menus;"
(click)="onClick($event,menu.link)"
[ngClass]="{'active':menu.active}">
{{menu.title}}
</div>
The method handling the click is as follows.
onClick(target, link) {
target.active = !target.active;
this.router.navigate([{ outlets: { primary: [""], menus: [link] } }]);
}
It seems that the value of target.active goes from undefined to true to false to true etc. but the style doesn't get set. (I'm printing out the whole component to the console and can't see the addition of the class' name.)
Question: What am I missing in this approach?
NB, I know how to resolve it by approaching it from a different angle. I set up a local variable keeping the index and setting it like shown here. The aim of my question is to learn to achieve the requested behavior in a more like-a-bossy way.
target here:
onClick(target, link) {
target.active = !target.active; <------------
this.router.navigate([{ outlets: { primary: [""], menus: [link] } }]);
}
doesn't refer to menu, it refers to the event. But based on your ngClass directive:
[ngClass]="{'active':menu.active}">
You need to set active to menu variable and so it can be done like this:
<div *ngFor="let menu of menus;"
(click)="onClick(menu,menu.link)"
[ngClass]="{'active':menu.active}">
{{menu.title}}
</div>
Instead of passing in the $event, send it the actual menu object. Like this:
<div *ngFor="let menu of menus;"
(click)="onClick(menu)"
[ngClass]="{'active':menu.active}">
{{menu.title}}
</div>
And in the component:
onClick(menu) {
menu.active = !menu.active;
this.router.navigate([{ outlets: { primary: [""], menus: [menu.link] } }]);
}

ionicPopup close on tap

I have a working ionicPopup which closes on a time limit. Is it possible to make it close on a single/double tap on anywhere on the screen? I know I can set a close button, but thats not really what I need. I need a simple dismiss method, and a tap on the screen I think is the more practical.
Code:
var errorPopup = $ionicPopup.show({
scope: $scope,
title: 'Unexpected Error',
templateUrl: 'error.html'
});
$timeout(function() {
errorPopup.close();
}, 3000);
}
And another question, I have a bunch of hyperlink tags within my html code. But when I run my app ionic puts a 1px border around each hyperlink. Is it possible to remove somehow the "" tag border. I know it should be a CSS thing, but I don’t want to modify the original ionic style, but would prefer to override that segment with another. Any gurus out there can help?
Solution: (Link)
<div class="col text-center">
<a class="item dash-link" id="link" href="#" onclick="window.open('http://www.example.com', '_blank', 'location=no'); return false;">
<img ng-src="img/icons/example.png" height="80" width="80"></a>
<br>
GMail
</div>
CSS:
#link {
text-decoration:none;
border:0;
outline:none;
}
This is a service to achieve this behavior.
Install
Install it with bower
$ bower install ionic-close-popup
Include the ionic.closePopup module in your app's dependencies:
angular.module('app', ['ionic', 'ionic.closePopup'])
Usage
Register your newly created popup to the closePopupService service :
var alertPopup = $ionicPopup.alert({
title: 'Alert popup',
template: 'Tap outside it to close it'
});
IonicClosePopupService.register(alertPopup);

CSS for jQueryMobile breaks AngularJS

These two URLs point to files which are identical except for one thing:
mobileCSS.html
noCSS.html
The mobileCSS.html file contains this line:
<link rel="stylesheet" href="/code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.css">
The noCSS.html file has the same line commented out:
<!--link rel="stylesheet" href="/code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.css"-->
Both pages use AngularJS to populate two <select> elements, one of which acts as a slave to the other. Both also contain a set of checkboxes to show the internal state of the model.
When jquery.mobile-1.4.3.css is used:
The initial values of the <select> elements are not displayed
The checkbox inputs do not update
Is this a known issue? Can you suggest a workaround for this?
Partial solution: correctedCSS.html
This reveals that jQueryMobile is not correctly updating, and that the decorations it adds hide the fact that the <select> and <checkbox> elements are being correctly updated by AngularJS:
.ui-checkbox .ui-btn {
z-index:0; /* in jquery.mobile-1.4.3.css, this is set to 2 */
}
.ui-select .ui-btn select {
opacity:1; /* in jquery.mobile-1.4.3.css, this is set to 0 */
}
Screenshots http://dev.lexogram.com/tests/angularJS/angularVSjqueryMobile.png
I am not too good at angular because I am also at learning stage but as per my knowledge something like below code can help.
JS
$scope.endonyms = [{code: "en", name: "English" }, { code: "fr", name: "Français" }];
$scope.selectedOption = $scope.endonyms[2];
HTML:
<select ng-options="endonym as endonym.name for endonym in endonyms"
ng-change="setSource()" ng-model="selectedOption">
The solution is as #Omar suggested:
you need to refresh checkboxes $(element).checkboxradio("refresh") and selectmenus $(element).selectmenu("refresh") after updating their values dynamically
However, timing is an important issue. When the AngularJS controller is first created, the jQueryMobile decorative elements have not yet been created, so they cannot be refreshed. Also, when AngularJS changes the value of a $scope property, the corresponding DOM element is not immediately updated, so calling "refresh" in the next line is pointless.
// Delay initial "refresh" until the page is ready
$(function () {
$("#source").selectmenu("refresh");
$("#target").selectmenu("refresh");
$("input[type='checkbox']").checkboxradio("refresh");
})
// Wait 1 millisecond before refreshing an item whose $scope property has been changed
function refreshChangedItems() {
window.setTimeout(function () {
$("input[type='checkbox']").checkboxradio("refresh");
$("#target").selectmenu("refresh");
}, 1)
}
You can find these fixes in solutionCSS.html

Highlight default button in ExtJS (3.x) MessageBox

is there an Ext-sanctioned way to highlight the default button (the one triggered by pressing Enter) in Ext.MessageBox?
Please note that I do not want to do that by focusing the button when the MessageBox is shown (in case of a "prompt" dialog I want the input element to have focus).
I know I can do that by adding a custom class to the button element but ... maybe there is a better and more Ext-like way of doing this?
Thanks.
In ExtJs 4 you can set the default button as follows:
Ext.MessageBox.defaultButton = buttonIndex;
Where 'buttonIndex' is the index of the button on the dialog. You need to do this before you call Ext.MessageBox.Show.
In short... no. Ext currently provides no method of highlighting a button in any of the Ext.MessageBox components, not via a config option anyway.
There are ways however, depending on the scenario. For example, if you're using Ext.MessageBox.show() (which you can actually use for all message boxes), then you can do something like...
new Ext.Msg.show({
title: 'Test',
msg: 'A sample message box with a button marked as default',
buttons: { ok: '<b>Submit</b>', cancel: 'Cancel' },
fn: function(btn) {
if(btn == 'ok') {
//do something
}
},
icon: Ext.Msg.WARNING
}
All we've done is add <b> tags to one of the buttons in our config, this would show it in bold obviously.
The other way that you've mentioned is to add a custom class and mark the button in a colour of text, you could even just add the class like we did with the <b> tags above to make it easier..
buttons: { ok: '<span class="highlighted-option">Submit</span>', cancel: 'Cancel' },
Other than this style of approach, or without extending the Ext.MessageBox class, there's no other way to achieve this.
Jaitsu has the best answer, but in case this might be useful to somebody else... here is a way to do that with styles.
The same trick can be applied to any other button (like: Window buttons).
Add this to your css:
.x-btn-default td.x-btn-mc {
outline: 1px dotted black;
}
Then define buttons like this:
...
,buttons: [
{
text: 'Ok',
,handler: handleFn
,cls: 'x-btn-default'
},{
text: 'Cancel',
,handler: handleFn
}
]
,...

Resources