Results 1 to 7 of 7

Thread: Compare two date fields and not allow save

  1. #1
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    764

    Default Compare two date fields and not allow save

    Hi,

    I want to compare two custom date fields. If date2 is before date1 then alert the user and do not allow the save.

    I have tried using the isafter validation in the vardefs.php but that is not working. I can however use the isbefore validation on date1 but then this show date1 as the issue when it is date2 I need to check..

    Any other ideas how this can be achieved. I have a custom view.detail.php where I can also check the dates and trigger a JavaScript popup but I cannot see how to then redirect the user back to the edit view after they press OK on the popup..

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  2. #2
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,638

    Default Re: Compare two date fields and not allow save

    Quote Originally Posted by chrislynch8 View Post
    Hi,

    I want to compare two custom date fields. If date2 is before date1 then alert the user and do not allow the save.

    I have tried using the isafter validation in the vardefs.php but that is not working. I can however use the isbefore validation on date1 but then this show date1 as the issue when it is date2 I need to check..

    Any other ideas how this can be achieved. I have a custom view.detail.php where I can also check the dates and trigger a JavaScript popup but I cannot see how to then redirect the user back to the edit view after they press OK on the popup..

    Rgds
    Chris
    The way I have done it is include a custom js file which has a function check_form that is a copy of the main check form with additions to compare the dates
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk

    SugarCRM Enterprise 6.5.12

  3. #3
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    764

    Default Re: Compare two date fields and not allow save

    Where can I find this check form?

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  4. #4
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,638

    Default Re: Compare two date fields and not allow save

    Quote Originally Posted by chrislynch8 View Post
    Where can I find this check form?

    Rgds
    Chris
    Chris

    /include/javascript/sugar_grp1.js

    Here is my modified version

    As well as doing some other checks it also prevents a problem with IE where if you click save twice you can end up with duplicate records

    Code:
    function check_form(formname) {
    	// check time on save
    	if (document[formname].check_time_flag == undefined) {
    	} else {
    		if (check_time('date_start','date_end',formname) == false) return false;
    	}	
    		
    	
    	
    	if (formname.match(/QuickCreate/)) {
    		
    		// use original
    			if(typeof(siw)!='undefined'&&siw&&typeof(siw.selectingSomething)!='undefined'&&siw.selectingSomething)
    		return false;return validate_form(formname,'');
    
    	} else {
    	
    
    	if (typeof (siw) != 'undefined' && siw
    			&& typeof (siw.selectingSomething) != 'undefined'
    			&& siw.selectingSomething)
    		return false;
    	if (validate_form(formname, '')) {
    		if (document.forms.length > 0) {
    			for (i = 0; i < document.forms.length; i++) {
    				for (j = 0; j < document.forms[i].elements.length; j++) {
    					var field = document.forms[i].elements[j];
    					if (field.type == "submit") {
    						if (field.value == "Save") {
    							// field.style.display = "none";
    							field.disabled = true
    						}
    					}
    				}
    			}
    		}
    		document[formname].submit()
    		// return true;
    
    	} else {
    			return false;
    	}
    	}
    	
    
    }
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk

    SugarCRM Enterprise 6.5.12

  5. #5
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    764

    Default Re: Compare two date fields and not allow save

    Thanks Mike,

    I'm completely lost. If found the file and I found the check_form function in it. In your code where you are checking the time on save. How is it doing that - I could find anything regarding check_time in the file..

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  6. #6
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,638

    Default Re: Compare two date fields and not allow save

    Quote Originally Posted by chrislynch8 View Post
    Thanks Mike,

    I'm completely lost. If found the file and I found the check_form function in it. In your code where you are checking the time on save. How is it doing that - I could find anything regarding check_time in the file..

    Rgds
    Chris
    Sorry to have confused you

    The standard sugar function consists of if(typeof(siw)!='undefined'&&siw&&typeof(siw.selec tingSomething)!='undefined'&&siw.selectingSomethin g)
    return false;return validate_form(formname,'');

    all the rest is mine

    the check_time is another custom function

    what it does is compare start & end times and if end time is less than start times it returns false and gives an error message

    hope that helps
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk

    SugarCRM Enterprise 6.5.12

  7. #7
    nileshdave is offline Sugar Community Member
    Join Date
    Nov 2007
    Location
    Gujarat
    Posts
    95

    Smile Re: Compare two date fields and not allow save

    Hello Chris,

    You can try out LogicHook feature in SuarCRM. You can compare those date fields on "Before Save" event in Logic hook

    To know for regarding Logic Hook Please follow this LINK

    Hope this helps to you.

    Regards,
    Nilesh Dave

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 2011-05-09, 02:43 PM
  2. 'Date Modify' and 'Date created' fields changes
    By shamimwilson in forum Help
    Replies: 0
    Last Post: 2009-03-31, 11:41 AM
  3. Replies: 6
    Last Post: 2008-04-21, 02:34 PM
  4. Replies: 2
    Last Post: 2008-01-31, 02:24 AM
  5. Replies: 8
    Last Post: 2007-04-16, 05:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •