Pregunta

I am developing a LiveCycle form that has a table on it that can have a variable amount of rows. I want to only validate it if there is data in one of the columns but not all of them. So I would skip the validation if the row is blank or all the columns in that row are filled in.

Any ideas how to do this. How would I loop through the rows of a table.

Thanks in advance, Paul

¿Fue útil?

Solución

I would tweat your answer a little bit by replacing resolveNodes that is quite slow.

  • In order to get row count you can use instanceManager TrainerForm._TrainerTable.count

  • To get a specific item from row list use <RowName>.all.item(index). Be carefull while using this construct because it requires a least one row. Row is a shourtcat for Row[0].

Here is your code with with my upgrades:

var rowCount = TrainerForm.TrainerTable._TrainerData.count;
for (var i=0;i<rowCount;i++)
{
    if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerName.rawValue == null && 
        TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerPrepHrs.rawValue == null && 
        TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerArea.selectedIndex == -1 && 
        TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerActivity.rawValue == null ) 
        ;//check the case where all rows are blank which is valid
    else
    {
        if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerName.rawValue == null)
        {
           TrainerTableValid = false;          
           TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerName.ui.#textEdit.border.fill.color").value = "255,0,0";
        }
        if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerPrepHrs.rawValue == null)
        {
            TrainerTableValid = false;          
            TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerPrepHrs.ui.#numericEdit.border.fill.color").value = "255,0,0";
        }
        if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerArea.selectedIndex == -1)
        {
            TrainerTableValid = false;          
            TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerArea.ui.#choiceList.border.fill.color").value = "255,0,0";
        }
        if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerActivity.rawValue == null)
        {
            TrainerTableValid = false;          
            TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerActivity.ui.#textEdit.border.fill.color").value = "255,0,0";
        }
    }
}  

Otros consejos

You can put your script in validate event of your cells or whole row. The result of validation script is determined by the last line result (true or false); To make validations failure visible you can set form level validation (File->Form Properties->Form Validation->Color Failed Fields).

Another approach (that I personally prefer) is setting field as required using code fieldName.manadatory = "error" when some conditions are met. In order to make field optional just put fieldName.manadatory = "disabled".

Here is what I ended up doing. First I made all fields optional. Then I execute this code from a click event of a button.

    var fields = xfa.resolveNodes("TrainerForm.TrainerTable.TrainerData[*]");
for (var i=0;i<fields.length;i++)
{
    if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerName.rawValue == null && 
        TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerPrepHrs.rawValue == null && 
        TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerArea.selectedIndex == -1 && 
        TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerActivity.rawValue == null ) 
        ;//check the case where all rows are blank which is valid
    else
    {
        if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerName.rawValue == null)
        {
            TrainerTableValid = false;          
            xfa.resolveNode("TrainerForm.TrainerTable.TrainerData[" + i + "].TrainerName.ui.#textEdit.border.fill.color").value = "255,0,0";
        }
        if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerPrepHrs.rawValue == null)
        {
            TrainerTableValid = false;          
            xfa.resolveNode("TrainerForm.TrainerTable.TrainerData[" + i + "].TrainerPrepHrs.ui.#numericEdit.border.fill.color").value = "255,0,0";
        }
        if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerArea.selectedIndex == -1)
        {
            TrainerTableValid = false;          
            xfa.resolveNode("TrainerForm.TrainerTable.TrainerData[" + i + "].TrainerArea.ui.#choiceList.border.fill.color").value = "255,0,0";
        }
        if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerActivity.rawValue == null)
        {
            TrainerTableValid = false;          
            xfa.resolveNode("TrainerForm.TrainerTable.TrainerData[" + i + "].TrainerActivity.ui.#textEdit.border.fill.color").value = "255,0,0";
        }
    }
}   
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top