cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MartinVargas
Helper V
Helper V

Manually Set Value in Date Field

Hello community, I am working with a portal in power apps. 

I am using a script to disable two days after the current date. This is working fine.

 

But it happens that if the user manually enters any date in the field "delivery date" it defeats the whole purpose of the script. That's why I'm looking for a way to remove/disable the "manually enter" option so that the user doesn't enter any date.

 

For example, the date shown was entered manually (06/05/2002). And I want everything that is entered in this field to be through the "Choose Date" button

MartinVargas_0-1652114424846.png

 

Can someone help me here? 

I would appreciate it guys

1 ACCEPTED SOLUTION

Accepted Solutions
MartinVargas
Helper V
Helper V

Thank you very much @Fubar @NatGeo, both solutions suit what I need.

View solution in original post

5 REPLIES 5
NatGeo
Helper II
Helper II

Hi @MartinVargas ,

one of the solution would be -adding the validation to the delivery date field - do not accept the current date +2 days. 

By disabling entry you may have some accessibility issues.

 

Hoping it helps.

NatGeo

MartinVargas
Helper V
Helper V

Hi @NatGeo Could you tell me an example of how to add a validation, I would greatly appreciate it.  I am new at this.

Fubar
Solution Sage
Solution Sage

This may not cover all the relevant events (you can add additional ones) but the following will generally stop the user entering in the input field 

$('#fieldname_datepicker_description').on('keypress paste', function (e) {
    e.preventDefault();
    return false;
});

 

NatGeo
Helper II
Helper II

Hi @MartinVargas 

 

You can add functionality provided by PowerApps Portal 

Add custom JavaScript - Power Apps | Microsoft Docs

or validate on the user entry, please see the code below:

$("#kg_dateofbirth").next().on("dp.change", function(e) {
       if ($("#kg_dateofbirth").val()==="Invalid date"){
	//error message if invalid date
  } 
       else if(!$("#kg_dateofbirth").val()){
	//error message if empty
}
        else{
            let controlVal = $("#kg_dateofbirth_datepicker_description").val();
            let today = new moment();
			today = moment(today).add(2,'d' ).format("YYYY-MM-DDT");
            controlVal = moment(controlVal).format("YYYY-MM-DDT");
            let a= moment(controlVal, "YYYY-MM-DDT", true);
            if(a.isValid() == true){
        if (controlVal > today) {
			$("#kg_dateofbirth").next().data("DateTimePicker").clear()
			//error message		
			}          
         }      
        }        
    });

 Hoping it helps!

NatGeo

MartinVargas
Helper V
Helper V

Thank you very much @Fubar @NatGeo, both solutions suit what I need.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel News & Announcements 768460.png

What's New in the Community?

Check out the latest News & Events in the community!

MPP IDEAS updated 768x460.png

Ideas

Discover ideas and concepts from users like you for how to use Power Pages and take your work to the next level.

Users online (1,978)