I have a "tabbed" application I'm developing.
I had used an array of objects stored in a Session variable to create these tabs and simply referenced it in the template. This renders what I'm looking for successfully and makes sense. The short version is:
<template name="tabs">
{{#each tabs}}
{{> Template.dynamic template=templateName data=getTemplateData}}
{{/each}}
</template>
But it appears to re-render every tab each time I add/remove a tab from the array and re-set the Session variable. I have way too many documents potentially referenced in each tab to make re-rendering all of them regularly a viable solution.
If I'm mistaken or was doing this wrong please let me know.
My second thought is to manually add/remove individual tabs from a regular array and reflect this via good old event-driven methods on the page. I have the template name I wish to use for a given tab and the data that needs to be used in it is stored in a Session variable with a unique name.
This should keep the other tabs from re-rendering when I add/remove another tab, but each tab still be subscribed to its own data individually.
I'm stuck on how to create a template instance via javascript so that I can insert it via jQuery. Thoughts?
Blaze.renderWithData was what I was looking for.
Related
I currently have a form with a related articles element that suggests the user related articles upon filling the form subject.
I'm trying to catch all the form submissions where a related article has been clicked.
I've created 2 triggers and 2 tags:
The first fires once the user clicks on one of the related articles.
The second trigger fires once the user clicked on the form submission button.
I've also created a Trigger group that combines these 2 triggers, however, I'm having trouble with storing the clicked article text from the first trigger and using it in the tag.
Eventually I want to send to analytics the form subject and the clicked article text.
I know this can be easily achieved with dataLayer, but unfortunately, I cannot add any code to the site source.
Any ideas on how to implement this without using dataLayer ?
Since standard variables are frequently overshadowed by new events, you probably should rewrite what you want to keep with a new name in the dataLayer. You do not need access to the site source to do so as long as your GTM snippet does not restrict GTM from adding custom html tags (blocking tag types is possible, but rarely used.)
You can do custom html tags with variable references like:
<script>
dataLayer.push({importantclick:{{click element}} })
</script>
fired on one event and create a new DataLayer variable to retrieve importantclick at a later event on the same page.
(If for some reason you really can't write to the dataLayer, then using custom javascript variables, you can instead examine the contents of the dataLayer yourself to see contents that were overshadowed or write data elsewhere in the window environment to be fetched by another variable. But both of those practices are highly discouraged when working with javascript variables.)
My app has a number of ambient properties, like the current CountryId, DocumentMode, etc. As I learned in a previous question, the current value of these properties should not be stored in the Session, but rather sent in the query string on every page request. So far so good.
So when I build a page, I want to arrange that all the action links look like this:
/controller/action?CountryId=x&DocumentMode=y&...
I can easily do this by checking the query string and slipping in the current value of each of these variables.
The question is, what's the right way to notify the app when one of the values changes?
Specifically, at the top of each view, I have a select dropdown that shows, e.g., all the countries. What should happen when you select a new one?
Right now, the change triggers a javascript function call that replaces the CountryId in the query string, and calls an action that just reloads the original page, but with the new CountryId set, and so the new action links are rebuilt. But this seems sort of kludgy. Is there a more elegant way to just update all the links on the page without needing a server refresh to do this? (I could always cook up some script to do this, but it doesn't seem trivial, and I don't want to reinvent the wheel if there's a built in way to do this.)
Any help much appreciated. Thanks!
You could put the part of the page that changes in a partial view and reload that view via AJAX each time a control is changed.
Partial rendering after page loaded
Alternatively you could just write some javascript to update all the links. Post some code and I'm sure you'll get some suggestions on a good way to write it.
I decided to keep things simple for the time being and just refresh the whole page, which recreates all of the links. My app is low volume and this suffices for now. If I ever need to build an app where the server can't be foolishly stressed like that, I'll see about the swap-in-place solution.
I have a question to understand the concept of ASP.NET with each client browser.
I am trying to update the XML on server when a user hits a particular page on my website.
This page is dynamic, but too large so I want it to load using an XML file also I have several drop downs on the page when user changes the value in drop down, I need to refresh the data based upon the selection, additionally my drop down is a custom designed here I do not get and selectedIndex change event.
So I'm using JQuery to get the changed value in my drop down and planning to read XML from jQuery and display the data.
But since the XML is updated on hit of the page on server, I want know, if multiple users hit the same page, will the data displayed as per each users selection or it will mix the data and show the last hits record.
If I'm not mistaken about your question, you basically ask the following:
You have an XML file, which is updated, on some event from user. The page, which is displayed to the user is based on this XML file. What info will users see, when multiple users are working with the application?
This greatly depends on how you are using that file. In general, if you try to write that file to disk each time, users will see the last update. Basically update from the last user.
However, you can synchronize access to this file, write the file on per-user basis and you will see a per-user output:
<data>
<selectedData user="user name">123</selectedData>
<!-- and so on -->
</data>
UPDATE:
For anonymous users this would not work well. However, if you need to store the selection only for the current user, you can use SessionState and not an XML file.
I would like to introduce a new way that it helped me to answer my above question.
What i did here is
on Page load we added all the information related to each section in different hidden fields.
suppose i have three section with my custom drop down!
What exactly we implemented is that on click on my custom drop-down, we separated the values from the hidden field with the separator we entered and displayed the data accordingly, small part of logic but it helped in displaying the data without post back.
and Jquery helps a lot to me for just changing the inner html of my block.
I have a form with a drop-down 'select' element that the user will sometimes need to add to. So, I added a link to open a Modal Frame form, created the Modal Frame form, and made its _submit() function add the new data to the table that holds options for the select element. Then it "returns" the new ID and name to the Javascript callback (the way Modal Frames do), and the JS callback adds the new element to the dropdown, and makes it the currently selected element in the browser, with JQuery. This all works great.
Finally, the user submits the original form, and gets the error "An illegal choice has been detected. Please contact the site administrator."
The form building function creates the option list from the database, which (I checked) DOES include the new option, so I'm guessing Drupal is using a cached version of the form rather than re-building it before it does the automatic validation. If you go back one page, then forward, the newly-added choice is there in the list.
I tried adding:
global $GLOBALS;
$GLOBALS['conf']['cache'] = FALSE;
to the function that builds the page with the problem, but it made no difference.
FYI: this is part of a multi-page form, if it matters.
I also thought about trying to add the option to the cached version of the "parent" form in the "child" form _submit() function, but don't know how to get the form_build_id of the "parent" form. Besides, that seems like way too much of a kludge (though I could be wrong about that).
Ideas?
You are submitting the form which is different then the time of form render so Drupal consider it as malicious input. If you want to skip that malicious check then add below line as property of your form in your_module_form() function.
'#DANGEROUS_SKIP_CHECK' => TRUE,
This will solve your problem but make sure that you are adding manual validation to protect from malicious inputs :). Hope this will help you.
I think you'd be better off using Drupal's AHAH functions to request an updated select element from a callback function. This way the cached form is rebuilt on the server side and you don't need to add the dreaded DANGEROUS_SKIP_CHECK. Here's a tutorial for Drupal 6:
http://randyfay.com/ahah
I am working on a page that has multiple sections and each section looks 'almost the same'. Having said that, I want to build the HTML on the server and render it for each section on the initial page load. On subsequent actions, I would do a ajax call and have the server return json data.
The other option is to 'hardcode' the HTML on the aspx page and have the JS do the necessary customizations for each section. The third option is to use an UpdatePanel and do everything server side.
Based on what should I be choosing what approach to use? What approach would you use for a page like this (think of it as a large page having sub sections on it)
Edit:
One section has HTML such as user's name, and a table where users can add dependents. Another section is almost the same except its for a 'contractor' so there's additional HTML such as previous work history, but this one has name (readonly) and a table to add dependents just like the first one. Other sections have more or less the same HTML.
A user can delete dependents as well, when that happens, I need to update the database and update the section to reflect one less dependent. I was hoping to make any subsequent actions as ajax calls that interact with the server and the database
In this situation I would make a control that used ajax calls to do its work. You could then have a few properties to set that would determine the minor differences between them. I'm also looking forward to another opinions/answers to this.
I would avoid the update panel at all costs it introduces a number of problems you won't have to deal with if you already understand JavaScript and ajax calls. You will also have much better performance without all the overhead included in the update panel.
Based on your update, it sounds like what you want is a custom control that would contain a bit of conditional logic to tweak the appearance based on its intended use. From there, use some ajax calls to communicate with the server when events such as adding/deleting dependents occur. So basically, what Mike said...
One option would be to create user controls for the "repeated" input fields, such as name and the grid for dependents.
Another option would be to use jQuery templates: http://plugins.jquery.com/project/jquerytemplate
I vote for not using an UpdatePanel for this :)