If text box is blank, show “Input Required” error, if txt box is not empty, make popup visible

%3CLINGO-SUB%20id%3D%22lingo-sub-2761678%22%20slang%3D%22en-US%22%3EIf%20text%20box%20is%20blank%2C%20show%20%E2%80%9CInput%20Required%E2%80%9D%20error%2C%20if%20txt%20box%20is%20not%20empty%2C%20make%20popup%20visible%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2761678%22%20slang%3D%22en-US%22%3EHello%3CBR%20%2F%3EI%20have%20a%20text%20box%20where%20a%20user%20must%20enter%20a%20number%20(price).%20There%20are%20also%20popup%20object%20grouped%20together.%20When%20a%20user%20clicks%20the%20submit%20button%2C%20the%20text%20box%20should%20be%20controlled%20if%20there%20a%20value%20there%20that%201.%20is%20greater%20than%20a%20value%20in%20a%20SharePoint%20list%20column%2C%20and%202%2C%20if%20the%20column%20in%20the%20SharePoint%20list%20is%20blank%2C%20it%20should%20check%20that%20the%20value%20in%20the%20text%20box%20is%20greater%20than%200.%20If%20it%20meets%20this%20Criteria%2C%20the%20popup%20(which%20contains%20all%20the%20pop%20up%20objects)%20should%20be%20displayed%20(visible).%3CBR%20%2F%3E%3CBR%20%2F%3EI%E2%80%99m%20pretty%20new%20to%20this%20and%20I%20went%20through%20a%20few%20if%20statemetns%20and%20tried%20to%20incorporate%20the%20update%20context%20unfortunately%20without%20success.%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20so%20much%20in%20advance%20for%20ur%20assistance%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2761678%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eif%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIsBlank()%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPopup%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerApps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EUpdateContext%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2764005%22%20slang%3D%22en-US%22%3ERe%3A%20If%20text%20box%20is%20blank%2C%20show%20%E2%80%9CInput%20Required%E2%80%9D%20error%2C%20if%20txt%20box%20is%20not%20empty%2C%20make%20popup%20visible%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2764005%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1149990%22%20target%3D%22_blank%22%3E%40katzgroup%3C%2FA%3E%26nbsp%3B!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20usually%20take%20a%20different%20approach%20to%20this%2C%20validating%20the%20user%20input%20before%20allowing%20them%20to%20submit.%26nbsp%3B%20See%20what%20you%20think%20of%20this%20idea%2C%20and%20let%20me%20know%20if%20you'd%20like%20to%20approach%20it%20differently%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20this%20example%2C%20I%20have%20a%20variable%20that%20holds%20my%20Sharepoint%20list%20item%20called%20varCurrentListItem%2C%20and%20in%20that%20list%20there%20is%20a%20number%20column%20called%20NumberColumn.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFirst%2C%20on%20my%20number%20input%20field%2C%20I%20have%20the%20following%20code%20in%20BorderColor%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EIf(IsNumeric(Self.Text)%2CRGBA(0%2C%2018%2C%20107%2C%201)%2CRGBA(255%2C0%2C0%2C1))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThis%20will%20put%20a%20red%20border%20around%20the%20text%20field%20if%20someone%20enters%20a%20non-numeric%20value.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%2C%20on%20my%20number%20input%20field%20OnChange%20event%2C%20I%20have%20the%20following%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EIf(%0A%20%20%20%20And(%0A%20%20%20%20%20%20%20%20IsBlank(varCurrentListItem.NumberColumn)%20%7C%7C%20IsEmpty(varCurrentListItem.NumberColumn)%2C%0A%20%20%20%20%20%20%20%20Value(Self.Text)%20%26gt%3B%20Value(varCurrentListItem.NumberColumn)%0A%20%20%20%20)%2C%0A%20%20%20%20If(%0A%20%20%20%20%20%20%20%20Value(Self.Text)%20%26gt%3B%200%2C%0A%20%20%20%20%20%20%20%20UpdateContext(%7BisValid%3A%20true%7D)%0A%20%20%20%20)%2C%0A%20%20%20%20UpdateContext(%7BisValid%3A%20false%7D)%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThis%20checks%20if%20the%20number%20entered%20into%20the%20text%20input%20is%20higher%20than%20the%20NumberColumn%2C%20or%20higher%20than%200%20if%20the%20NumberColumn%20is%20blank%20(is%20Use%20IsEmpty%20and%20IsBlank%20because%20I%20never%20quite%20remember%20which%20one%20SharePoint%20validates%20against%20for%20a%20blank%20number%20column).%26nbsp%3B%20the%20%22%7C%7C%22%20allows%20us%20to%20evaluate%20against%20multiple%20criteria%20in%20our%20if%20statement.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20now...%22isValid%22%20will%20only%20be%20true%20if%20we%20have%20a%20valid%20number%20that%20fits%20our%20criteria.%26nbsp%3B%20We%20can%20use%20it%20to%20allow%20someone%20to%20click%20on%20the%20%22Submit%22%20button.%26nbsp%3B%20My%20submit%20button%20has%20the%20following%20code%20in%20DisplayMode%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EIf(isValid%2CDisplayMode.Edit%2CDisplayMode.Disabled)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20finally%2C%20the%20OnChange%20on%20my%20submit%20button%20looks%20like%20this%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EUpdateContext(%7BvarShowPopup%3Atrue%7D)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20I%20can%20use%20varShowPopup%20to%20show%20my%20popup%2C%20placing%20this%20in%20the%20Visible%20property%20of%20my%20popup%20group%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EvarShowPopup%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20attached%20a%20copy%20of%20the%20zipped%20.msapp%20file%20to%20this%20post%20for%20reference.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELet%20me%20know%20if%20you%20need%20any%20more%20assistance%20around%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3EBrendan%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor
Hello
I have a text box where a user must enter a number (price). There are also popup object grouped together. When a user clicks the submit button, the text box should be controlled if there a value there that 1. is greater than a value in a SharePoint list column, and 2, if the column in the SharePoint list is blank, it should check that the value in the text box is greater than 0. If it meets this Criteria, the popup (which contains all the pop up objects) should be displayed (visible).

I’m pretty new to this and I went through a few if statemetns and tried to incorporate the update context unfortunately without success.

Thank you so much in advance for ur assistance
1 Reply

Hi @katzgroup !

 

I would usually take a different approach to this, validating the user input before allowing them to submit.  See what you think of this idea, and let me know if you'd like to approach it differently:

 

For this example, I have a variable that holds my Sharepoint list item called varCurrentListItem, and in that list there is a number column called NumberColumn.

 

First, on my number input field, I have the following code in BorderColor:

 

 

If(IsNumeric(Self.Text),RGBA(0, 18, 107, 1),RGBA(255,0,0,1))

 

 

This will put a red border around the text field if someone enters a non-numeric value.

 

Then, on my number input field OnChange event, I have the following:

 

 

If(
    Or(
        And(
            !IsBlank(varCurrentListItem.NumberColumn) || !IsEmpty(varCurrentListItem.NumberColumn),
            Value(Self.Text) > Value(varCurrentListItem.NumberColumn)
        ),
        And(
            IsBlank(varCurrentListItem.NumberColumn) || IsEmpty(varCurrentListItem.NumberColumn),
            Value(Self.Text) > 0
        )
    ),
    If(
        Value(Self.Text) > 0,
        UpdateContext({isValid: true})
    ),
    UpdateContext({isValid: false})
)

 

 

This checks if the number entered into the text input is:

 

1. If the SharePoint column is blank/empty,, higher than 0

2. If the SharePoint column is not blank/empty, higher than the value in the column

 

I Use IsEmpty and IsBlank because I never quite remember which one SharePoint validates against for a blank number column.  the "||" is equivalent to "or" and allows us to evaluate against multiple criteria in our if statement.

 

So now..."isValid" will only be true if we have a valid number that fits our criteria.  We can use it to allow someone to click on the "Submit" button.  My submit button has the following code in DisplayMode:

 

 

If(isValid,DisplayMode.Edit,DisplayMode.Disabled)

 

 

This code only enables the button to be clicked if "isValid" is true.

 

And finally, the OnSelect on my submit button looks like this:

 

 

UpdateContext({varShowPopup:true})

 

 

So when we click the button (which can only be clicked if our number is already valid), we set varShowPopup to true.

 

Now I can use varShowPopup to show my popup, placing this in the Visible property of my popup group:

 

 

varShowPopup

 

 

 

I've attached a copy of the zipped .msapp file to this post for reference.

 

Let me know if you need any more assistance around this.

 

 

Cheers,

Brendan