Stop users from removing subdocuments in Autoform - meteor

What should happen is a user can add a subdocument with the big [+] button, but cannot remove it without a prompt. Basically just deleting the [-] button. How do I do that? Can I do that?
If it can't be done I have other solutions to my problem, but that seems to defeat the purpose of the using this package.

Yes, you can remove the [-] button.
For add new document you have to write a following code in the events.
Template.TemplateName.events({
"click .autoform-add-item" :function(){
//This allow to remove the current [-] button as well.
setTimeout(function(){
$('.autoform-remove-item').remove();
});
},
});
For add edit document you have to add the remove [-] button code in onRendered block as well, like :
Template.TemplateName.onRendered(function () {
$('.autoform-remove-item').remove();
});
#Note :: Please make sure then you have "autoform-add-item" class on [+] button and "autoform-remove-item" on [-] button. You can check these classes using inspect element.

Related

Meteor - Remove Event Map Listeners

Meteor makes it easy to add event listeners natively, but how would one go about removing an event listener natively?
Template.dashboard.events({
'click #dashboard-ul li': function(e) {
}
});
I want to remove the click event on '#dashboard-ul li' in the above through Blaze or Meteor's native remove event listener methods.
I could not find any mention of event removal in the meteor docs besides removing the element outright.

How can I simulate a click event on an anchor tag without actually calling click or refreshing?

I am using meteor with iron router and meteors standard blaze tempting.
I have an ul set up so that when one of my li items is clicked its containing anchor tag is clicked on using the function click. The only problem is that when that a is clicked with the function it counts as another click on my li and my menu isn't toggling right.
I am wondering if there is a way to call the pathFor without actually calling a click function.
Thanks for any help!
Update, here is the code its working along with a pretty standard drop down nav. I am not sure if I can catch that event the same as a jquery event since I think it is the standard browser click event working on the [0], but I think I should be able to make a function that matches href to route and call Router.go
Template.nav.rendered = () ->
# set initial page view and take care of refeshes
currentPageHtlm = getCurrentPage(window.location.pathname)
$('#currentPage').find('span').html(currentPageHtlm)
$("li").on "click", () ->
#simulate anchor click and set currentPage session
$(this).find("a")[0].click()
Session.set 'pageName', getCurrentPage($(this).find("a").attr("href"))
currentPageHtlm = Session.get 'pageName'
$('#currentPage').find('span').html(currentPageHtlm)
# toggle nav and arrow if mobile view
if $('.smOnly').css('display') != 'none'
$('#nav').slideToggle('slow')
$('#dropArrow').toggleClass('fa-caret-square-o-down fa-caret-square-o-up')
It sounds like you're looking for a way to programatically redirect from JS rather than via UI interaction, in which case you need to use Router.go('ROUTE_NAME'), as per the docs (you can use the route name as in pathFor as an alternative to supplying the actual path).

Jquery browser history js - same action doesnt fire second time - no state change workaround

Using browserstate/history.js
All my links are running through the history adapter:
History.Adapter.bind(window,'statechange',function() {
// do some stuff here
});
but if a user clicks the same link twice in a row then the second time it will not run since there is no 'statechange'. What is the solution for this?
You can add random data to differentiate the actions:
History.replaceState( {randomData: window.Math.random()}, '', url);
That way statechange will always fire.
Found answer here https://github.com/browserstate/history.js/issues/293

Backbone menu refresh handling

I am using yeoman workflow http://yeoman.io/ ,
I have build a simple menu layout to handle the menu css :
var menu = new Backbone.Layout({
template: "layouts/menu",
className: "menu",
events: {
'click a': 'changeActive'
},
changeActive: function(e) {
$(e.target).parent().siblings('.active').removeClass('active');
$(e.target).parent().addClass('active');
...
It work fine but I am facing a problem in which I bump into very often,
when user clicks on browser's refresh button of course it doesn't remember the state and display
the initial state.
What is the best way to solve that ?
You could save the last selected value to the cookie or to the localStorage and inside the initialize method make it active.
You can update the hash and save selected value there. On initialize just get it and make proper menu active.

FullCalendar beforeLoad & afterLoad Callbacks

Are there any callbacks in FullCalendar that trigger before Calendar load or after the calendar completely loads? Thank you for the help!
loading: function (bool) {
if (bool)
$('#loadingImg').show();
else
$('#loadingImg').hide();
//Possibly call you feed loader to add the next feed in line
},
If any event rendering or fetching for ALL the sources is happening it will be TRUE otherwise it will trigger and goto to FALSE
There is no other way to determine if a particular feed has loaded or is being loaded.
You would have to implement your own logic using the loading
where you would use
$('#calendar').fullCalendar('addEventSource', 'diaryFeed.aspx?style=Basic');
wait for load to finish and trigger to add the next source.. etc
There are a few options you can use,
loading can be used to trigger events while loading and after loading More Info
or you can use eventRender and eventAfterRender to trigger before each event is rendered and after each event has rendered.
Hope this helps!

Resources