This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Calendar Past-Date Issue


  1. sjones
    Member

    Hello Yuniar. I just realized that users can select dates previous to today's date, when filling out a form. I did a search through this forum and another user questioned whether you could limit start dates and end dates. You directed them to the calendar developer's site. The instructions for the calendar product states you can input a min start date and max end date, but I would have to update the js code daily. This is not a viable option.

    I also see, on that site, that three users have asked similar questions, but no answer. I have re-asked the question and hopefully will receive a response. Their support seems no where as good as yours. I also noted they now have a newer version of the calendar out and no longer support the version you have implemented into machforms.

    Posted 15 years ago #
  2. sjones
    Member

    Bump.

    Hoping someone has an answer for this problem. The calendar developer's website says to put the following in to limit dates that can be picked from a calendar.:

    Calendar.setup({
    cont: "sample1",
    min: 20090726,
    max: 20091225
    });
    Unfortunately this would mean me going in every day and changing the MIN value. Surely there is some sort of command that sets the current date as the minumum date.

    Thanks you.

    Posted 15 years ago #
  3. yuniar

    That seems to be true for the newest version of the calendar script, which I just realized it's no longer free to use :(

    Anyhow, try to do this, edit your calendar.js file, search around line 1804, you will find this function:

    function selectDate(cal) {
    	var p = cal.params;
    	var update = (cal.dateClicked || p.electric);
    	year = p.inputField.id;
    
    	day = p.baseField + '_2';
    	month = p.baseField + '_1';
    
    	document.getElementById(month).value = cal.date.print('%m');
    	document.getElementById(day).value = cal.date.print('%e');
    	document.getElementById(year).value = cal.date.print('%Y');
    }

    change that block of code with this one:

    function selectDate(cal) {
    	var p = cal.params;
    	var update = (cal.dateClicked || p.electric);
    	year = p.inputField.id;
    	day = p.baseField + '_2';
    	month = p.baseField + '_1';
    
    	var today = new Date();
    	if(cal.date < today){
        	alert('You can not choose past date!');
        	return false;
        }	
    
    	document.getElementById(month).value = cal.date.print('%m');
    	document.getElementById(day).value = cal.date.print('%e');
    	document.getElementById(year).value = cal.date.print('%Y');
    }

    that should set your calendar to not allow past dates selection.


    MachForm Founder

    Posted 15 years ago #
  4. sjones
    Member

    That worked great Yuniar. Thanks.

    Posted 15 years ago #
  5. sjones
    Member

    Okay, I hate to be more trouble, but I have a couple more questions.

    Firstly let's say I have 6 forms, 3 of which I don't care what date is picked, and 3 that will not allow a date before today to be picked. The calendar.js file resides in another subdirectory and all forms seem to share it. If I put in the code to stop earlier dates, that means my 3 forms that don't care which date is picked, also get blocked. I tried moving calendar.js to form 1's directory (as a test) but then the calendar function would not work so I moved it back.

    Also, since this is for a hotel reservation system, I realized that I really don't want reservations taken for tomorrow, today or previous days, not just previous days. I could not figure out how to manipulate the code to allow this.

    Thanks

    Posted 15 years ago #

RSS feed for this topic

Reply