[jQuery] Re: Form Plugin and Validation, I am totally lost even after doing the research.

2009-06-04 Thread Bob Schellink


Hi John,

johnHoysa wrote:

Actually I jumped the gun but hopefully soon I will figure this out.




My understanding is that both ajaxSubmit and validate are registered 
on the Form submit event. So both events are fired at the same time. 
Thus when the form's beforeSubmit callback fires, the validation 
already executed. At least that is what I've observed :)


To get both working together I did the following (perhaps you can 
enhance it to fit your needs):



  // Define an indicator for validation success/fail status
  var valid = false;

  // Setup the validation options
  var validationOptions {

  // this callback is invoked on successful validation
  submitHandler: function(form) {
  // we set valid indicator to true
  valid = true;
  },

  // this callback is invoked on failed validation
  invalidHandler: function(form, validator) {
  // we set valid indicator to false
  valid = false;

  } // add further validation options here
  }

  var formOptions {
beforeSubmit:  preSubmit,
// define more form options here
  }

  // The Form preSubmit handler
  function preSubmit(formData, jqForm, options) {
// If form validation failed we return false to stop Form submit
if (!valid) {
return false;
}
  }

// Define
jQuery(#form).validate(validationOptions);
jQuery('#form').ajaxForm(formOptions);


Hope this is helpful.

kind regards

bob



[jQuery] Re: Taconite - remove surrogate div

2008-11-12 Thread Bob Schellink


In case someone runs into the same issue, I've attached a patch to 
remove the temporary div.


In short this snippet moves the content after the div and then removes 
the div. Not sure if this will have nasty side effects though.


regards

bob


Index: jquery.taconite.js
--- jquery.taconite.js Base (BASE)
+++ jquery.taconite.js Locally Modified (Based On LOCAL)
@@ -150,6 +150,7 @@
 continue;
 }
 var cdataWrap = cmdNode.getAttribute('cdataWrap') || 
$.taconite.defaults.cdataWrap;

+var unwrap = [];

 var a = [];
 if (cmdNode.childNodes.length  0) {
@@ -178,7 +179,13 @@
 log(invoking command: $(', q, ')., cmd, '('+ arg 
+')');

 }
 jq[cmd].apply(jq,a);
+
+// Unwrap cdataWrap element contents
+while (el = unwrap.shift()) {
+var jel = $(el);
+jel.after(jel.html()).remove();
 }
+}
 // apply dynamic fixes
 if (doPostProcess)
 postProcess();
@@ -217,6 +224,8 @@

 function handleCDATA(s) {
 var el = document.createElement(cdataWrap);
+// Add cdataWrap element, to be unwrapped later
+unwrap.push(el);
 el.innerHTML = s;
 return el;
 };



Bob Schellink wrote:


Hi Mike,

Thanks for your feedback. Your solution does work in the scenario I 
described where only one link is used. However it is possible to return 
multiple elements for example:


taconite
 append
  a href=...hello/a
  a href=...hi/a
 /append
/taconite

To provide some context, I am integrating taconite into a component 
framework and do not have much control over the commands and their content.


Hmm would it work to unwrap (does that even make sense) the div contents?

kind regards

bob


Mike Alsup wrote:

In order to do this taconite places the CDATA content inside a div
element. However after the command is executed the div is left in the 
DOM.


So after a bit of back and forth between browser and server we end up
with a large hierarchy of divs.


Hi Bob,

Could you test this function to see if it fixes the issue for you?
(just replace the current one in Taconite)

function handleCDATA(s) {
var el = document.createElement(cdataWrap);
el.innerHTML = s;

// remove wrapper node if possible
var $el = $(el), $ch = $el.children();
if ($ch.size() == 1)
return $ch[0];
return el;
};


Thanks.

Mike








[jQuery] Taconite - remove surrogate div

2008-11-10 Thread Bob Schellink


Hi all,

The taconite plugin provides the ability to wrap results in CDATA tags 
which allows one to return special characters such as '' and ''.


Example command:

taconite
 replace select=#link![CDATA[
  a href=/counter.htm?link=myidcount=1 id=linkHi/a
 ]]/replace
/taconite

In order to do this taconite places the CDATA content inside a div 
element. However after the command is executed the div is left in the DOM.


So after a bit of back and forth between browser and server we end up 
with a large hierarchy of divs.


Would it be possible to enhance Taconite to remove this div after the 
command is executed? Or any other suggestion on how to remove the div?


kind regards

bob


[jQuery] Re: Taconite - remove surrogate div

2008-11-10 Thread Bob Schellink


Hi Mike,

Thanks for your feedback. Your solution does work in the scenario I 
described where only one link is used. However it is possible to 
return multiple elements for example:


taconite
 append
  a href=...hello/a
  a href=...hi/a
 /append
/taconite

To provide some context, I am integrating taconite into a component 
framework and do not have much control over the commands and their 
content.


Hmm would it work to unwrap (does that even make sense) the div 
contents?


kind regards

bob


Mike Alsup wrote:

In order to do this taconite places the CDATA content inside a div
element. However after the command is executed the div is left in the DOM.

So after a bit of back and forth between browser and server we end up
with a large hierarchy of divs.


Hi Bob,

Could you test this function to see if it fixes the issue for you?
(just replace the current one in Taconite)

function handleCDATA(s) {
var el = document.createElement(cdataWrap);
el.innerHTML = s;

// remove wrapper node if possible
var $el = $(el), $ch = $el.children();
if ($ch.size() == 1)
return $ch[0];
return el;
};


Thanks.

Mike





[jQuery] Re: Using taconite to append javascript and stylesheets

2008-10-31 Thread Bob Schellink


Hi Ricardo,

ricardobeat wrote:


This works though: $('head')[0].appendChild($('script type=text/
javascript src=what.js')[0])



Thanks, that is pretty slick. Much better than the approach I took of 
tracking scripts by appending place holder tags in head.


Just to summarize, my approach to ensure javascript and stylesheet 
resources are only loaded once, is to validate against guard functions 
before appending the resource.


An example guard function:

/*
 * This function checks if the given script already exists in the
 * document head section. It uses the following two rules:
 *
 * External scripts are checked against their 'src' attribute.
 * Inline scripts are checked against their 'id' attribute.
 *
 * @param script is a script DOM element.
 */
function canAddScript(script) {
  var id = script.getAttribute(id);
  if(id) {
// Check if another script exists with the same id attribute
if($('#'+id).length) {
  log('script with id: ' + id + ' already exists');
  return false;
}
  }
  var src = script.getAttribute(src);
  if (src) {
// Check if another script exists with the same src attribute
if($('script[src='+src+']').length) {
  log('script with src: ' + src + ' already exists');
  return false;
}
  }
  return true;
}


kind regards

bob




On Oct 29, 9:11 pm, Bob Schellink [EMAIL PROTECTED] wrote:

Hi Ricardo,

ricardobeat wrote:

You don't need a plug-in to do that:
$('head')
   .append('link href=css/geral.css rel=stylesheet /')
   .append('script type=text/javascript src=calendar.js/
script')

Using the above method (or taconite) I've noticed that JQuery does not
actually append the script element to head. At least according to
Firebug. Is this the expected behavior?

One of the things I want to achieve is that scripts should only be
appended once for a page. However if JQuery does not add the script to
head there is nothing to check against in a future call which might
add the same script again.

Should I bypass JQuery and manually add the script tags to head?

kind regards

bob






[jQuery] Re: Using taconite to append javascript and stylesheets

2008-10-29 Thread Bob Schellink


Hi Ricardo,

ricardobeat wrote:

You don't need a plug-in to do that:

$('head')
   .append('link href=css/geral.css rel=stylesheet /')
   .append('script type=text/javascript src=calendar.js/
script')



Using the above method (or taconite) I've noticed that JQuery does not 
actually append the script element to head. At least according to 
Firebug. Is this the expected behavior?


One of the things I want to achieve is that scripts should only be 
appended once for a page. However if JQuery does not add the script to 
head there is nothing to check against in a future call which might 
add the same script again.


Should I bypass JQuery and manually add the script tags to head?

kind regards

bob


[jQuery] [Taconite] Using taconite to append javascript and stylesheets

2008-10-28 Thread Bob Schellink

Hi all,

I am using the Taconite (http://malsup.com/jquery/taconite/) plugin to 
dynamically append external scripts (script) and stylesheets 
(link) to the page head section. Inspired by the Taconite example 
Demo1, I manage to get external scripts working, however stylesheets 
only seems to work in Firefox, not IE.

Here is the Taconite markup I'm using:

taconite

 !-- Works in FF and IE --
 append select=head
 script type=text/javascript src=calendar.js/
 /append

 !-- Works in FF but not IE --
 append select=head
 link rel=stylesheet type=text/javascript 
href=calendar.css/
 /append
/taconite


Is this scenario supported by Taconite or should I rather the eval 
tag for appending stylesheets?

kind regards

bob