Knockout验证更改错误消息

时间:2017-12-01 21:37:26

标签: typescript knockout.js knockout-validation

我试图更改特定字段的错误消息。这是我到目前为止的最新情况。

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class MainMethod {

 static ToB ArrayToB[] = new ToB [4];   
 static Diet ArrayDiet [] = new Diet [4];
 static DietAttributes ArrayDietAtributes [] = new DietAttributes [4];
 static Activities ArrayActivities [] = new Activities [6];

 static int arrayCount = 0;


   public static void main(String[] args) 
    {
        String csvFile = "/Users/dylan.ramirez/Documents/COMPUTER 
SCIENCE/IA/IAVersion1/IAVersion1/src/iaversion1/DATABASE - Sheet1.csv";
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";

    try {

        br = new BufferedReader(new FileReader(csvFile));
        while ((line = br.readLine()) != null) {

            //this line separates each column of the csv file
            String[] databaseColumn = line.split(cvsSplitBy);

            //this variables store each individual column
            String sTypeOfBody = databaseColumn[0];
            String sAppearance = databaseColumn[1];
            String sDietDescription = databaseColumn[2];
            String sFoodExample = databaseColumn [3];
            String sBicepsExercise = databaseColumn [4];
            String sGluteusExercise = databaseColumn [5];
            String sAbdominalsExercise = databaseColumn [6];
            String sQuadricepsExercise = databaseColumn [7];
            String sPectoralsExercise = databaseColumn [8];
            String sDietName = databaseColumn [9];
            String sBodyNutrientsPercent = databaseColumn [10];          
            String sMuscularEnduranceActivity = databaseColumn [11];
            String sAgilityActivity = databaseColumn [12];
            String sPowerActivity = databaseColumn [13];
            String sBalanceActivity = databaseColumn [14];
            String sCoordinationActivity = databaseColumn [15];
            String sSpeedActivity = databaseColumn [16];
            String sNutrients = databaseColumn [17];


            ToB ToBTemp = new ToB(sTypeOfBody, sAppearance);
            ArrayToB[arrayCount] = ToBTemp;

            Diet DietTemp = new Diet(sDietName, sDietDescription);
            ArrayDiet[arrayCount] = DietTemp;

            DietAttributes DietAttributesTemp = new DietAttributes(sDietName, sDietDescription, sNutrients, sBodyNutrientsPercent, sFoodExample);

            Activities ActivitiesTemp = new Activities (sMuscularEnduranceActivity, sAgilityActivity, sPowerActivity, sBalanceActivity, sCoordinationActivity, sSpeedActivity, sBicepsExercise, sGluteusExercise, sAbdominalsExercise, sQuadricepsExercise, sPectoralsExercise);
            ArrayActivities [arrayCount] = ActivitiesTemp;

            arrayCount = arrayCount + 1;


        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    } 
    System.out.println(ArrayToB[3].getTypeOfBody());

}

}

我已经有了在页面顶部单独显示消息的代码。如果该字段是隐藏的

scrollToIndex={11}           <= Item index to scroll
scrollToAlignment="end"      <=the top of the container

由于某种原因,消息保持不变。请帮助谢谢。

我试过的其他事情:(点击提交按钮后)

var errorMsg = fieldHidden ? "Please do something" : "Hidden field error Msg";

ko.validation.rules["validation"] = {
    validator: (value) => {
        if (ko.validation.utils.isEmptyVal(value)) {
            return true;
        }
    },
    message: errorMsg
};

即使这在我检查chrome调试器时更改了消息,仍会显示旧消息。

0 个答案:

没有答案