UA-17470720-3

Jump to content


Photo
- - - - -

Validation error message in sectionActions.willInsertItem?


  • Please log in to reply
4 replies to this topic

#1 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 14 March 2016 - 04:59 AM

Hello,

 

I am trying to implement validation on class definitions, I assume the best place to do it is sectionActions.willInsertItem and/or sectionActions.willUpdateItem (the same validation logic would apply to both inserts and updates). The question I have is what is the best way to focus on the field/cell that should be corrected?

 

Thank you,

Radu


  • Adjuramum likes this

#2 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 515 posts
  • LocationAustralia
Reputation: 168
Popular

Posted 14 March 2016 - 11:33 PM

in something like this you can set the cell background colour, font etc to something RED and when is valid set it to clear or what ever colour it was before

 

can also then use the property whereby the nav DONE button is not enabled when fields are invalid

 

// Objective-C
cellActions.valueIsValid = ^BOOL(SCTableViewCell *cell, NSIndexPath *indexPath)
{
    BOOL valid = NO;

    if([cell isKindOfClass:[SCTextFieldCell class]])
    {
        SCTextFieldCell *textFieldCell = (SCTextFieldCell *)cell;

        // Make sure the password field is at least 8 characters long
        if([textFieldCell.textField.text length] >= 8)
            valid = YES;
    }

    return valid;
};

// Swift
cellActions.valueIsValid =
{
    (cell, indexPath)->Bool in

    var valid = false

    if let textFieldCell = cell as? SCTextFieldCell
    {
        // Make sure the password field is at least 8 characters long
        if countElements(textFieldCell.textField.text) >= 8
        {
            valid = true
        }
    }

    return valid
}

  • Tarek likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#3 RaduGrama

RaduGrama

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 29 posts
  • LocationTampa, FL
Reputation: 6
Good

Posted 14 March 2016 - 11:41 PM

Hi Ozie,

 

If I use cellActions.valueIsValid:

  • Does this method get called every time the user changes the value in a field or moves to another field?
  • Does this method get called when a cell is created as well so an initial indication that the field does not contain a valid value (bold font, red background, etc.) can be set?
  • Is this cell specific or it is called for all cells and if for all cells what would be the best approach to determine the field/property in the model associated with the cell (different fields/model properties have different business rules).

Thank you,

Radu



#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 515 posts
  • LocationAustralia
Reputation: 168
Popular

Posted 14 March 2016 - 11:42 PM

dunno.. plug in the code and run it and test :) 


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 15 March 2016 - 09:49 AM

Hi Radu,

 

  • Does this method get called every time the user changes the value in a field or moves to another field?

 

Yes.

 

Does this method get called when a cell is created as well

 

Yes the whole form is first validated at creation time to determine if the 'Done' button should be enabled.

 

Is this cell specific or it is called for all cells

 

Called for all cells.

 

what would be the best approach to determine the field/property in the model associated with the cell

 

You typically access the cell's bound value using the 'boundValue' property. To access the object itself, you can use the 'boundObject' property. You can also determine the name of the property that the cell represents by using the 'boundPropertyName' property.

 

Hope this helps.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users