Jquery validation in IE 8 - Object doesn't support this property or method for drop down box - validationrules

I'm using jquery validation to validate my form. It works well on text box but when I try to validate a drop down, it throws me an "Object doesn't support this property or method" error in IE 8 only. It works fine in FF or Chrome. Not sure if I did something wrong. I even try not to use the custom "notEqual" function to test it and replace it with the build in "required" method. Again, it's giving me the same thing.
Please help! Much appreciate!
Here's my code:
$(document).ready(function () {
jQuery.validator.addMethod("notEqual", function(value, element, param) {
return this.optional(element) || value != param;
}, "Please specify a different (non-default) value");
$("#form1").validate({
focusInvalid: false,
focusCleanup: true,
debug: false,
onkeyup: false,
onclick: true,
onsubmit: true,
onkeyup: false,
rules: {
<%=titleText.UniqueID %>: {
required: true
},
<%=startDateText.UniqueID %>: {
required: true ,
date: true
},
<%=endHourText.UniqueID %>: {
notEqual: "00"
},
submitHandler: function(form) {
form.submit();
}
},
messages: {
<%=titleText.UniqueID %>: {
required: "Please provide a name for the event."
},
<%=startDateText.UniqueID %>: {
required: "Please enter a date for the event.",
date: "Please enter a valid date."
},
<%=endHourText.UniqueID %>: {
notEqual: "Please enter a valid end time."
}
}
});
});
Thanks in advance!!

Aha, I found this out the hard way myself just the other day. JQuery Validator attempts to access the 'form' property of the select element and if this is null, JQuery Validator blows up with the error you have described.
I'm not entirely sure why element.form would be null for you. I was never entirely clear why it was null for me either, unless it was related to the fact that validation was firing even as the HTML containing this particular select element was being removed from the DOM.
I solved this by adding a check to my validation code so that I only validate a select element where element.form != null. You may also need to check that element.form exists as in Firefox there's no such property:
if (element.form && element.form != null) { ... }

Related

How to get radiobutton by default checked with bootbox prompt

I am able to display radio buttons using bootbox prompt. But I am not getting the checked radio button by default. How to do that . Here is my code to displaying radio buttons.
bootbox.prompt({
title: "This is a prompt with a set of Radiobutton inputs!",
inputType: 'radio',
inputOptions: [
{
text: 'EU Format',
value: '1',
checked: true,
},
{
text: 'Standard Format',
value: '2',
}
],
callback: function (result) {
console.log(result);
}
});
I have added checked: true, and tried with checked : "checked" , but not sure these both not working . Any help would be greatly appreciated.
This is actually covered in the documentation, here. I've also answered this previously, but since I don't have a link to that answer at the moment, this is what you need to do:
bootbox.prompt({
title: "This is a prompt with a set of Radiobutton inputs!",
inputType: 'radio',
value: '1', /* value sets the initial checked item */
inputOptions: [
{
text: 'EU Format',
value: '1',
checked: true,
},
{
text: 'Standard Format',
value: '2',
}
],
callback: function (result) {
console.log(result);
}
});
The only difference between radiobuttons and checkboxes is that you can only set a single value with radios. NOTE THAT THE TYPES MUST MATCH. In your example, '1' would work, but 1 would not, since the former is a string, whereas the latter is a number. We don't do any explicit type coercion when checking the value attribute.
Since you're referencing the radio type, I assume you're using the 5.x version? If so, I have a work-in-progress update to the docs here, until I can push the 5.x version out. The old docs are still valid, but it (obviously?) doesn't document some of the new features.

KeystoneJS dependsOn not saving its new value when disappear

User.add({
name: { type: Types.Name, required: true },
userid: { type: Types.Text, initial: true, required: true },
exceed_login_attempt: {
type: Types.Boolean,
default: false,
label: 'Exceeded Invalid Login Attempts',
dependsOn: { exceed_login_attempt: true }
}
});
I have here a checkbox input field exceed_login_attempt I want this to be display in AdminUI if the value is true (checked). If I unchecked that the value is false and the checkbox will disappear - this is fine.
But when I save it the checkbox value which is false is not save. After rendering the page the value is still true, which means it displays again the checkbox.
On KeystoneJS database documentation it is mentioned that:
To improve the usability of the Admin UI, it is possible to hide fields when no value is set, or depending on the value of other fields.
A field can depend on the value of other fields. But in your posted code, the exceed_login_attempt field, depends on its own value, which doesn't look right to me:
exceed_login_attempt: {
...
dependsOn: { exceed_login_attempt: true }
}
I'm not sure, maybe you intend to use collapse rather than dependsOn:
collapse [Boolean] Displays an + add link in the admin UI when the field has no value. Will completely hide field UI when noedit is also set to true, when the field has no value

X-Editible, setValue doesn't seem to work

I'm trying to work out how to update the value passed back from a script, with X-Editible. The HTML is:
<h2 id="store-editible-url" data-type="text" data-pk="1" data-name="store_url">test value</h2>
And the script:
$(document).ready(function(){
$('#store-editible-url').editable( {
url: 'http://www.example.com/cgi-bin/art/my-store.cgi',
onblur: "submit",
placeholder: "Click to set a custom URL",
emptytext: "Click to set a custom URL",
params: { action: "update_store_url" },
success: function(response, newValue) {
$('#store-editible-url').editable('setValue',"foo",true);
}
});
});
Here is a fiddle, although it doesn't work as such (due to the fact the URL isn't a valid one).
The idea is that the server does some sanitising, and then passes the value back to the browser. Howeve4r, for simplicity sake my demo code just does:
$('#store-editible-url').editable('setValue',"foo",true);
I don't get an error, but it's not updated. Here is the fiddle:
http://jsfiddle.net/nrtrdo39/1/setValue
Any ideas?
I'm no expert on x-editable, but as far as I understand, you will need to just do $('#store-editible-url').editable("foo",true); on order to set the value of property "foo" or for data- type options, $('#store-editible-url').editable('option','pk',1);

Row Expander checking condition

I have Grid with "rowexpander". with this I am able to expand the row, and able to show the content .i.e. html checkbox.
Now my requirement is the in my DB I got the value true or false. So depending upon the value i.e. true I want show check box with checked.
Here is my code.
plugins: [
{
ptype: 'rowexpander',
rowBodyTpl:
['<ul><li><input type="checkbox" name="" checked={marginAccess} ><span>Margin Access for Quote</span></li></ul> ']
}
Now {marginAccess} when is it true I want to show ""
i.e. checked = checked
I am not able to do this, Can you please suggest me ?
Create a virtual member in your model. One which will return 'checked/unchecked' for true/false value of other field. Like this:
{ name: 'marginAccess_str', type: 'string', convert: function(v, r) {
if (r.get('marginAccess'))
return 'checked';
else
return 'unchecked';
}},
And then use marginAccess_str in your template.

sencha list paging plugin

I'm trying to use sencha touch's listpaging plugin. But there is almost no good( or bad ) documentation about how to use it and i'm confused.
When i activate the plugin in my list
this.myList = new Ext.List({
store: this.myStore,
plugins: [{
ptype: 'listpaging',
autoPaging: false
}],
itemTpl: '...'
});
a 'Load More' text and a loading image is added to the end of the list.
But i don't know how to configure my store to enable this plugin to be able to load more data.
App.regStore('MyStore', {
model: 'myModel',
proxy: {
type: 'ajax',
url: 'http://mydomain.com/json?howmany=10&page=1',
reader: {
type: 'json',
root: 'results'
}
}
});
App.stores.myStore = Ext.StoreMgr.get('MyStore');
How can i configure my store so when i tap "Load more", the store brings up page 2 and add them to the list automatically?
I've had a similar issue with the ListPaging plugin in SenchaTouch 2, and managed to sort out the 'load more' message behaviour when the end of the data set is reached.
This builds on what John Gordon has come up with (regarding specifying the pageSize and clearOnPageLoad config options), since these properties seem to be the same in Senchatouch 2. I haven't looked at SenchaTouch 1.x in detail. In SenchaTouch 2, all config options must be defined in a config property:
Ext.define('MessagingApp.store.MessageThreads', {
extend : 'Ext.data.Store',
requires: ['MessagingApp.model.MessageThread'],
config:
{
model: 'MessagingApp.model.MessageThread',
autoLoad: false,
clearOnPageLoad: false, // This is true by default
pageSize: 10, // This needs to be set for paging
proxy: {
type: 'jsonp',
pageParam: 'currentPage',
limitParam: 'pageSize',
url: APIURL + '/message-app-service/GetMessageThreads',
reader: {
type: 'json',
rootProperty: 'Data'
}
}
}
});
In the view, where we specify the plugins, we can override the 'load more' and 'no more records' messages:
{
xtype:'dataview',
store:'MessageThreads',
id:'threadList',
itemTpl:Ext.create('Ext.XTemplate',
'<!-- template markup goes here -->',
{
//custom helper functions here
}
),
plugins:[
{
xclass:'Ext.plugin.ListPaging',
autoPaging: true,
// These override the text; use CSS for styling
loadMoreText: 'Loading...',
noMoreRecordsText: 'All messages loaded'
}
]
}
The issue is that while our web service returns an array of records for a particular page, there is no overall total count property, which is needed for the plugin to determine when all records have been loaded. Hence as it is, the 'Load more' message will remain (issue #1 in the accepted solution). So in the init function of our controller, we have to attach an event handler for the load event on the store to hook into when a new page of data is received:
Ext.define('MessagingApp.controller.Messages',
{
extend: 'Ext.app.Controller',
config:
{
views: [
'MessageThreads',
// Other views referenced by this controller
],
stores: [
'MessageThreads'
],
refs:
{
// References to UI elements by selector...
}
},
init: function() {
// Other internal initialisation...
this.control(
{
// Selector-object pairs...
});
// Provide a means to intercept loads of each page of records
var threadStore = Ext.getStore('MessageThreads');
threadStore.addBeforeListener('load', this.checkForThreadListEnd, this);
},
// Remaining controller functions...
});
In the handler, we realise that we've reached the end of the data set when the number of records returned is less than the page size. If the total record count is a multiple of the page size, the last 'page' will have an empty array. Once the end of the data set has been identified, we update the totalCount config property of the store:
checkForThreadListEnd: function(store, records, isSuccessful) {
var pageSize = store.getPageSize();
var pageIndex = store.currentPage - 1; // Page numbers start at 1
if(isSuccessful && records.length < pageSize)
{
//Set count to disable 'loading' message
var totalRecords = pageIndex * pageSize + records.length;
store.setTotalCount(totalRecords);
}
else
store.setTotalCount(null);
},
// Other controller functions...
Because this is a 'before' event handler, this property will be crucially updated before the plugin decides whether to display the 'load more' or 'no more records' messages. Unfortunately, the framework doesn't provide a means to hide the 'no more records' message, so this would have to be done via CSS.
Hope this helps.
I'm having problems finding good documentation, too, but I can at least answer your question. You need to add pageSize to your store, clearOnPageLoad as well, if you want to not clear out what was already loaded. Her's my code:
Ext.regStore('publicresources', {
model: 'PublicResource',
autoLoad:false,
remoteFilter:true,
sortOnFilter:true,
pageSize: 15,
clearOnPageLoad: false,
sorters: [
{
property : 'distance',
direction: 'ASC'
}
]
});
My outstanding issues that I'm looking into are:
How to turn off the "More" element when there are no more records to load
How to detect that there are no more records to load, and where to put that detection code.
How to keep the list at the location that the user was at. Each load jumps back to the 1st item in the list
Good luck!
Remember also that this works only server side currently.
Forum thread http://www.sencha.com/forum/showthread.php?105193-Store-pageSize
In regards to the "load more vs. no more records" message -
If you are writing a custom proxy (example here A Sencha Touch MVC application with PhoneGap), you set the total records in the returned Operation.
If the total records are not yet known, you can do something like the below, where,
1) if you are returning the requested limit of records, set the total to something larger than the records the store will now hold
2) if returning < the requested limit of records, set the total to 1 (to force the "no more records message")
//return model instances in a result set
operation.resultSet = new Ext.data.ResultSet({
records: contacts,
//total : contacts.length,
total : contacts.length === operation._limit ? (operation._limit * operation._page +1) : 1,
loaded : true
});
//announce success
operation.setSuccessful();
operation.setCompleted();
//finish with callback
if (typeof callback == "function") {
callback.call(scope || thisProxy, operation);
}
Just to add what worked for me..
If your server returns a totalCount and you want to set it you can use the totalProperty in the reader
reader: {
type: 'json',
rootProperty: 'results',
totalProperty: 'resultCount'
}