[Proto-Scripty] Appending a template evaluation to an HTML element.
Hi. I've implemented a simple add new user button to my amend users page. The user list is only about 20 people, with name/email/pin/contracts/delete options. The button calls a template evaluation and that is within an update ... $('vsNewUsers').update($('vsNewUsers').innerHTML + tmpl_NewUser.evaluate({NewUserID : --i_NewUserID})); All working fine. I like how it works, but I wonder how I can just append the result of the evaluation. How do I take a template and append the results to vsNewUsers. vsNewUsers is a tbody element and the template is a tr element with all the td's needed. var tmpl_NewUser = new Template('trtdinput type=text name=User[#{NewUserID}][Username] value= maxlength=200 size=50 //tdtdinput type=text name=User[#{NewUserID}][Email] value= maxlength=200 size=50 //tdtdinput type=number name=User[#{NewUserID}][PIN] value= maxlength=4 //tdtdinput class=vsaAllContracts type=checkbox name=User[#{NewUserID}][AllContracts] value=1 id=allContracts_#{NewUserID} //tdtdinput type=text name=User[#{NewUserID}][ContactIDs] value= maxlength=200 disabled=disabled size=50 /input type=hidden name=User[#{NewUserID}][ContactIDs] value=/tdtdbutton class=vsaChooseContracts bold id=selectContracts_#{NewUserID}Select contracts/button/tdtdinput type=checkbox name=User[#{NewUserID}][Delete] value=#{NewUserID} //td/tr'); I'm thinking no. Regards, Richard. -- Richard Quadling. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Appending a template evaluation to an HTML element.
On 17 August 2010 12:59, Phil Petree phil.pet...@gmail.com wrote: === HTML save as index.html: html head script src=prototype.js/script /head body form id=myform table id=keytable trtdKeyword/tdtdinput type=text name=keyword_1/td/tr /table /form input type=button onclick=addkeyword() value=Add Keyword input type=button onclick=dosubmit() value=Submit div id=result style=padding:5px; /div script var nextkeyid = 2; function addkeyword() { var elTR = $('keytable').insertRow( -1 ); var elTitleTD = elTR.insertCell( -1 ); elTitleTD.appendChild( document.createTextNode( 'Keyword' ) ); var elInput = document.createElement( 'input' ); elInput.type = 'text'; elInput.name = 'keyword_'+nextkeyid; nextkeyid++; var elInputTD = elTR.insertCell( -1 ); elInputTD.appendChild( elInput ); } function dosubmit( ) { new Ajax.Updater( 'result', 'add.php', { method: 'post', parameters: $('myform').serialize() } ); } /script /body /html === Serverside PHP save as add.php: Post Result:br/ ?php var_export( $_POST ) ? === On Tue, Aug 17, 2010 at 7:30 AM, Richard Quadling rquadl...@gmail.com wrote: On 17 August 2010 12:01, Phil Petree phil.pet...@gmail.com wrote: That's in the expando example that comes with prototype.js 1.6x On Tue, Aug 17, 2010 at 6:35 AM, Richard Quadling rquadl...@gmail.com wrote: Hi. I've implemented a simple add new user button to my amend users page. The user list is only about 20 people, with name/email/pin/contracts/delete options. The button calls a template evaluation and that is within an update ... $('vsNewUsers').update($('vsNewUsers').innerHTML + tmpl_NewUser.evaluate({NewUserID : --i_NewUserID})); All working fine. I like how it works, but I wonder how I can just append the result of the evaluation. How do I take a template and append the results to vsNewUsers. vsNewUsers is a tbody element and the template is a tr element with all the td's needed. var tmpl_NewUser = new Template('trtdinput type=text name=User[#{NewUserID}][Username] value= maxlength=200 size=50 //tdtdinput type=text name=User[#{NewUserID}][Email] value= maxlength=200 size=50 //tdtdinput type=number name=User[#{NewUserID}][PIN] value= maxlength=4 //tdtdinput class=vsaAllContracts type=checkbox name=User[#{NewUserID}][AllContracts] value=1 id=allContracts_#{NewUserID} //tdtdinput type=text name=User[#{NewUserID}][ContactIDs] value= maxlength=200 disabled=disabled size=50 /input type=hidden name=User[#{NewUserID}][ContactIDs] value=/tdtdbutton class=vsaChooseContracts bold id=selectContracts_#{NewUserID}Select contracts/button/tdtdinput type=checkbox name=User[#{NewUserID}][Delete] value=#{NewUserID} //td/tr'); I'm thinking no. Regards, Richard. -- Richard Quadling. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. Can you point me to the URL please? -- Richard Quadling. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. Now in comparison, that process (creating elements, assigning properties, etc.) _LOOKS_ a lot more effort. What do most developers do? Templates or createElement? -- Richard Quadling. -- You received this message because you are subscribed to the Google Groups Prototype
[Proto-Scripty] Safari problem in Accordion with Flash content
Can anyone explain why I might see the following? I have a simple Accordion effect made with Scriptaculous: var tog = function(){ var params = {duration:0.2}; if (this.next('p')) { Effect.toggle(this.next('p'),'blind',params); }else{ if(this.up().next('p')){ Effect.toggle(this.up().next('p'),'blind',params); } } }; It works fine in all browsers. But while watching the page in Safari's error console, and clicking the header over a Flash movie, I see an incrementing error related to the Flash movie itself: Failed to load resource: cancelled. If I open and close the accordion effect, hiding and showing the Flash movie, the page works perfectly, but that error repeats every time after the first time the movie shows. The other header on the page reveals a static JPEG image, and nothing happens in the console when that opens and closes. Here's a live example, extracted from my Rails project, if you want to see it in the wild. http://scripty.walterdavisstudio.com/problem Thanks, Walter -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] scriptaculous causes body background to fail on safari and chrome
Hi all, i have a very simple document: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head titleBG fail/title style type=text/css body { background-color: #00; color:#ff; } /style script type=text/javascript src=lib/prototype.js/script script type=text/javascript src=lib/scriptaculous.js/script /head body h1Hello/h1 /body /html On chrome and safari, the black background stops right after the h1 hello. On safari, if i ask for the page source code, right after the code window appeared, the background gets back to normal. If i remove scriptaculous inclusion, no more problem. If i move the style declaration after the script tags, no more problem (it took really long to figure out what went wrong...). Am i missing something? is it recommended to move the style declarations (or imports i tested with external css) after scripts? is it a safari and chrome (webkit?) bug? Thanks Guillaume -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: 4 different browsers - 4 different responses
I don't see how this went too far afield at all -- at least not nearly enough to bother to comment on it. Richard had some Prototype-related code that wasn't doing what he wanted and he also mentioned the target attribute not being standards and so not wanting to use it. I told him how I do what he's doing (with Prototype) and asked in what way he thought `target` wasn't standard. He answered me. Hardly a digression worth commenting on. Sometimes discussions do start out related to Prototype and then branch a bit into general web development (much more than this one did), which I don't see as using the list incorrectly at all. A question that didn't involve Prototype or scripty *at all* would be off-topic. -- T.J. On Aug 17, 7:32 am, Lapis petter.env...@gmail.com wrote: Oh hai ;) Interesting as it may be.. does prototype.js or scriptaculous have anything to do Witherspoon this? Or did I just subscribe to some random HTML/HTTP chat? Sorry, getting morning coffee now... /P On 13 Aug, 17:06, Richard Quadling rquadl...@gmail.com wrote: Hi. I want to press a button to open a new tab showing a PDF file. Currently, I have ... a id=vsFax target=_blank href=/index.php title=Jobsheet class=formButtons button id=vsViewJobsheetButtonView jobsheet/button /a and each browser resulted in a different outcome (Chrome:new tab OK, Firefox:2 new tabs both OK, IE:nothing, Safari:new window) I know that target is a no-no for standards (and it seems IE is the only one obeying it this time around!). So. How do I do this? The real url is supplied at runtime via an AJAX request. I can assign it to whatever is needed. I could just style the a as a button ... is that possible? Any suggestions? Regards, Richard Quadling. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: Appending a template evaluation to an HTML element.
On 17 August 2010 16:34, T.J. Crowder t...@crowdersoftware.com wrote: Hi, The original code: $('vsNewUsers').update($('vsNewUsers').innerHTML + tmpl_NewUser.evaluate({NewUserID : --i_NewUserID})); ...will require the browser to spin through the tree inside vsNewUsers and create an equivalent HTML string to give you; then tear down that tree, parse the HTML you give it back (including re-parsing the stuff it just gave you), re-instantiate a lot of elements that look exactly the same as the previous one (plus the new ones at the end), re- calculate the layout of the previous elements (and then the additional ones), etc. (Layout can be expensive with tables, too, so...) Seems like unnecessary work. :-) Granted the browser's going to do it really fast, but still. Also, you'd lose any event handlers you'd hooked up to the elements in there and any other data you may have stored on them. If your user is using IE, any elements that Prototype's already extended will have to be re-extended (which takes non-trivial time on big tables). Fortunately, Element#insert[1] is for exactly this situation: $('vsNewUsers').insert({ bottom: tmpl_NewUser.evaluate({NewUserID : --i_NewUserID}) }); [1] http://api.prototypejs.org/dom/element/insert/ Vis-a-vis using `new Element` rather than HTML: Parsing HTML and showing the result on the page is fundamentally what browsers do, and they do it really, _really_ fast. When rendering HTML, they can work directly with their internal structures. When you use the DOM API, you lose that benefit and have to work through the browser's DOM API - internal structures mapping. And you're doing all of your work in an interpreted (or at least compiled-on-the-fly) language. Net result? Markedly slower -- like an order of magnitude -- to go through the DOM API vs. using HTML. This isn't a Prototype thing at all, it's just the nature of browsers and what they're optimized for. I actually did a test page (not much of one) a little over a year back when answering a question for someone that showed this in action, and through the wonder that is 'net search: http://pastie.org/521342 HTH, -- T.J. Crowder Independent Software Consultant tj / crowder software / com www.crowdersoftware.com On Aug 17, 2:09 pm, Phil Petree phil.pet...@gmail.com wrote: I would think that Creating elements is less limiting... but I have no idea what most developers do. On Tue, Aug 17, 2010 at 8:29 AM, Richard Quadling rquadl...@gmail.comwrote: On 17 August 2010 12:59, Phil Petree phil.pet...@gmail.com wrote: === HTML save as index.html: html head script src=prototype.js/script /head body form id=myform table id=keytable trtdKeyword/tdtdinput type=text name=keyword_1/td/tr /table /form input type=button onclick=addkeyword() value=Add Keyword input type=button onclick=dosubmit() value=Submit div id=result style=padding:5px; /div script var nextkeyid = 2; function addkeyword() { var elTR = $('keytable').insertRow( -1 ); var elTitleTD = elTR.insertCell( -1 ); elTitleTD.appendChild( document.createTextNode( 'Keyword' ) ); var elInput = document.createElement( 'input' ); elInput.type = 'text'; elInput.name = 'keyword_'+nextkeyid; nextkeyid++; var elInputTD = elTR.insertCell( -1 ); elInputTD.appendChild( elInput ); } function dosubmit( ) { new Ajax.Updater( 'result', 'add.php', { method: 'post', parameters: $('myform').serialize() } ); } /script /body /html === Serverside PHP save as add.php: Post Result:br/ ?php var_export( $_POST ) ? === On Tue, Aug 17, 2010 at 7:30 AM, Richard Quadling rquadl...@gmail.com wrote: On 17 August 2010 12:01, Phil Petree phil.pet...@gmail.com wrote: That's in the expando example that comes with prototype.js 1.6x On Tue, Aug 17, 2010 at 6:35 AM, Richard Quadling rquadl...@gmail.com wrote: Hi. I've implemented a simple add new user button to my amend users page. The user list is only about 20 people, with name/email/pin/contracts/delete options. The button calls a template evaluation and that is within an update ... $('vsNewUsers').update($('vsNewUsers').innerHTML + tmpl_NewUser.evaluate({NewUserID : --i_NewUserID})); All working fine. I like how it works, but I wonder how I can just append the result of the evaluation. How do I take a template and append the results to vsNewUsers. vsNewUsers is a tbody element and the template is a tr element with all the td's needed. var tmpl_NewUser = new Template('trtdinput type=text name=User[#{NewUserID}][Username] value= maxlength=200 size=50 //tdtdinput type=text
Re: [Proto-Scripty] Re: prototype to populate select box via ajax
T.J. YOU are a gentleman AND a scholar! I looked everywhere for how to do this! Hopefully this post will move up in the search engines and others can find it! One other question on this... What if the XML response is: data other stuffmore and more/stuff /other states state code=CACalifornia/state state code=AKArkansas/state /states /data How do I need to format this line? states = response.responseXML response.responseXML.firstChild; (I think I need a good primer on how this is working... LOL) Thanks, Pete On Tue, Aug 17, 2010 at 2:32 AM, T.J. Crowder t...@crowdersoftware.comwrote: Hi, The XML can be in whatever form you find useful to parse. Here's a complete example that handles an XML response that looks like this: statesstate code=CACalifornia/statestate code=AKArkansas/ state/states Code (also -- more readably -- here: http://pastie.org/1097106): * * * * !DOCTYPE HTML html head meta http-equiv=Content-type content=text/html;charset=UTF-8 titleTest Page/title style type='text/css' body { font-family: sans-serif; } #log p { margin: 0; padding:0; } /style script type='text/javascript' src='http://ajax.googleapis.com/ajax/ libs/prototype/1.6.1.0/prototype.jshttp://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js '/script script type='text/javascript' document.observe('dom:loaded', function() { $('btnGo').observe('click', go); function go() { new Ajax.Request(getlist.jsp, { onSuccess: getlistSuccess, onFailure: getlistFailure, on0:getlistFailure }); } function getlistSuccess(response) { var states, state, selbox, options; // Validate response states = response.responseXML response.responseXML.firstChild; if (!states || !states.tagName || states.tagName != states) { getlistFailure(response); return; } // Get the select box and its options array (not really an array) selbox = $('selectbox'); options = selbox.options; // Loop the states for (state = states.firstChild; state; state = state.nextSibling) { options[selbox.options.length] = new Option( state.firstChild.nodeValue, state.getAttribute(code) ); } } function getlistFailure(response) { log(getlist call failed); } var write = log; function log(msg) { $('log').appendChild(new Element('p').update(msg)); } }); /script /head body input type='button' id='btnGo' value='Go' brselect id='selectbox'/select hr div id='log'/div /body /html * * * * HTH, -- T.J. Crowder Independent Software Consultant tj / crowder software / com www.crowdersoftware.com On Aug 16, 10:00 pm, Phil Petree phil.pet...@gmail.com wrote: I've looked everywhere for a solution to this and hacked around with it all day with no luck. How do we populate a select box using xml data obtained from an ajax request. If what I get back from the fillin example is this: data firstJack/first lastFlash/last emailjfl...@candlestick.com/email /data And I want to add a list of US states to a select box but obviously we can't have stateAK/state stateAL/state So question 1 is: What's the correct format for the XML response? My 2nd question is how do I break out the seperate parts from the transport response? transport.responseXML.getElementsByTagName('$fieldname')[0].firstChild.node Value; My 3rd question is, will the following code work for populating the select box? opt.text = Alaska; opt.value = AK; $(DropDownStateList).options.add(opt);// Assign text and value to Option object -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: prototype to populate select box via ajax
Here is a completed function that will populate a select box with data in an XML format (XML format below): // fill the select dropdown list box // @ajax response (transport as returned above) // @id of the select field (defaults to elFieldName // @xml_data_node_name (our dataset uses 'state') function fillSelectList(transport, select_id, xml_data_node) { var states, state, selbox, options; // Get validate response states = transport.responseXML.getElementsByTagName(xml_data_node); $(select_id).options.length = 1; for(var i = 0; i states.length; i++) { var value = states[i].getAttribute('value'); var name= states[i].getAttribute('name'); // i+1 allows us to skip over the first item in the // pulldown which prompts the user to Pick One $(select_id).options[i+1] = new Option(name, value, null, false); } } XML Data data firstJohn/first lastDoe/last emailj...@gmail.com/email states state value=AL name=Alabama / state value=GA name=Georgia / state value=FL name=Florida / state value=CA name=California / /states /data Thanks to T.J. and Colin Mollenhour for their help on this! -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Should be simple - using up() with css class
up() looks for a matching ancester in the DOM, not a sibling (brother) that was before it in the DOM. I think this will work : $('part-47').up().down('tr.sd_type').id On 17 août, 22:47, Rhiq ndba...@gmail.com wrote: I obviously don't get the way up() works. Using the generated HTML below: tr class=sd_type ChildOfClass10 ChildOfCat8 open id=type-18 td class=sd_typeType: Test Type/td td a href=# onclick=renameType(18)Rename/a | a href=# onclick=addPart(18)Add Part/a | In Use (3) /td /tr tr id=part-43 class=sd_part ChildOfType18 ChildOfClass10 ChildOfCat8 td class=sd_partPart: dfgdfg (0)/td td a href=# onclick=renamePart(43)Rename/a | a href=# onclick=removePart(43)Remove/a /td /tr tr id=part-46 class=sd_part ChildOfType18 ChildOfClass10 ChildOfCat8 td class=sd_partPart: sdfgs (0)/td td a href=# onclick=renamePart(46)Rename/a | a href=# onclick=removePart(46)Remove/a /td /tr tr id=part-47 class=sd_part ChildOfType18 ChildOfClass10 ChildOfCat8 td class=sd_partPart: fdsgre (0)/td td a href=# onclick=renamePart(47)Rename/a | a href=# onclick=removePart(47)Remove/a /td /tr If I try the following: alert($('part-47').up('tr.sd_type').id) I get an error saying that it is undefined. Does it make sense to anyone what I am trying to do? Is there a way for me to do what I would like? I am trying to make changes to the first tr with the class sd_type above the current tr (in this case tr#part-47). Any help would be awesome. Nathan -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Weird Select list behavior in IE7
Hi all, I have solved my issue by by using: this.select.options[i] = new Option(opt.value, opt.key, null, false); rather than this.select.insert({'bottom': new Element('option', {'value':opt.key}).update(opt.value)}); Thanks to everyone who gave this some thought! (Sorry for the top post) -- Nich On Aug 17, 10:26 am, Nich nicholas.stei...@narthollis.net wrote: Hi all, I have a site that i need to make work in IE7 but i have run into a very frustrating issue. I am using django to generate the form for a payment request. As a part of this form the user can input one or more breakdowns for this payment, Because I only want to write the form once I duplicate the breakdown using element.clone() and then clean it up before creating a new form. I have this all working quite nicely. The issue I'm having is when I combine this behavior with some code I have to allow the filtering of select lists. The issue occurs in IE7 and IE8 when rendering as IE7. It does not occur in any other browser I have tested. Here is an example: http://www.lccare.org.au/~nsteicke/selectissue/ To replicate, use IE7 or IE8 in IE7 compatibly mode, then click '+ Add Breakdown' and then filter the new select list and try and expand the list. Any assistance you can offer in solving this issue would be great. -- Nich -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.