Pregunta

not sure exactly how to ask this question so please bear with me. I have 6 fields i need to check to see if they are empty. I thought the code below would do the job, but its not. I dont think im understanding the code and how it works correctly and am having trouble finding help on other forums/posts/questions. Im not looking for someone to solve this(would like to learn instead of just getting an answer) but if anyone knows where i can read up on this sort of if statement i would appreciate it. I found some info on creating a list out of this and then checking if the list is empty, but am having trouble figuring out how that would work in this situation. Again, not sure if i asked the question correctly or provided enough info, so please ask if you need more info.

if FormSet.IsEmpty(CurrentForm, "ADD_COMP1_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP2_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP3_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP4_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP5_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP6_ADDRESS"):
    Rule.Violated = True
   else:
    Rule.Violated = False

To summarize, i need to check 6 fields, if they and of them are empty, i need the rule to violate. If any of these fields are filled in then the rule should not violate.

¿Fue útil?

Solución

so i guess i really am new to this stuff, all i needed to do was fix the indent on "else:" should have been at the same indent level as "if"

if FormSet.IsEmpty(CurrentForm, "ADD_COMP1_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP2_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP3_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP4_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP5_ADDRESS") and \
   FormSet.IsEmpty(CurrentForm, "ADD_COMP6_ADDRESS"):
    Rule.Violated = True
else:
    Rule.Violated = False
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top