Bom dia galera, seguinte, estou com um problema quando seto meu currenteLocale no flex para espanhol, estou internacionalizando um sistema e no espanhol o flex deixa o campo allowedFormatChars
como null, no português o campo vem da seguinte forma allowedFormatChars="/- \."
. O problema só ocorre no espanhol, ocorre o problema, alguém já passo por isto?
Nunca passei por isso com o flex, porem nunca internacionalizei um sistema flex, mas se voce colocar no construtor uma setagem para essa propriedade, passando o valor que desejar
Assim, se eu setar ele pega tranquilamente, o problema que é tenho um componente validator extendido de DateValidator, assim faço a validação de datas no flex, porém vários problemas ocorrem no próprio validator do flex, erros de variáveis ficarem null como esta, erro de acesso a propriedade objetos que não existem.
Este problema que ocorreu no fonte que mostrei acima eu já havia resolvido, mas
o problema que ocorre mas abaixo é no seguinte fonte do DateValidator.
/**
* Convenience method for calling a validator
* from within a custom validation function.
* Each of the standard Flex validators has a similar convenience method.
*
* @param validator The DateValidator instance.
*
* @param value A field to validate.
*
* @param baseField Text representation of the subfield
* specified in the value parameter.
* For example, if the <code>value</code> parameter
* specifies value.date, the <code>baseField</code> value is "date".
*
* @return An Array of ValidationResult objects, with one ValidationResult
* object for each field examined by the validator.
*
* @see mx.validators.ValidationResult
*/
public static function validateDate(validator:DateValidator,
value:Object,
baseField:String):Array
{
var results:Array = [];
// Resource-backed properties of the validator.
var allowedFormatChars:String = validator.allowedFormatChars;
var inputFormat:String = validator.inputFormat;
var validateAsString:Boolean = validator.validateAsString;
var resourceManager:IResourceManager = ResourceManager.getInstance();
var validInput:String = DECIMAL_DIGITS + allowedFormatChars;
var dateObj:Object = {};
dateObj.month = "";
dateObj.day = "";
dateObj.year = "";
var dayProp:String = baseField;
var yearProp:String = baseField;
var monthProp:String = baseField;
var advanceValueCounter:Boolean = true;
var monthRequired:Boolean = false;
var dayRequired:Boolean = false
var yearRequired:Boolean = false;
var valueIsString:Boolean = false;
var foundMonth:Boolean = false;
var foundYear:Boolean = false;
var objValue:Object;
var stringValue:Object;
var n:int;
var i:int;
var temp:String;
n = allowedFormatChars.length;
for (i = 0; i < n; i++)
{
if (DECIMAL_DIGITS.indexOf(allowedFormatChars.charAt(i)) != -1)
{
var message:String = resourceManager.getString(
"validators", "invalidFormatChars");
throw new Error(message);
}
}
if (value is String)
{
valueIsString = true;
stringValue = String(value);
}
else if (value is Number)
{
valueIsString = true;
stringValue = String(value);
}
else if (value is Date)
{
var date:Date = value as Date;
objValue = {year: date.fullYear,
month: date.month + 1,
day: date.date};
}
else
{
objValue = value;
}
// Check if the validator is an object or a string.
if (!validateAsString || !valueIsString)
{
var baseFieldDot:String = baseField ? baseField + "." : "";
dayProp = baseFieldDot + "day";
yearProp = baseFieldDot + "year";
monthProp = baseFieldDot + "month";
if (validator.required && (!objValue.month || objValue.month == ""))
{
results.push(new ValidationResult(
true, monthProp,"requiredField",
validator.requiredFieldError));
}
else if (isNaN(objValue.month))
{
results.push(new ValidationResult(
true, monthProp, "wrongMonth",
validator.wrongMonthError));
}
else
{
monthRequired = true;
}
if (validator.required && (!objValue.year || objValue.year == ""))
{
results.push(new ValidationResult(
true, yearProp, "requiredField",
validator.requiredFieldError));
}
else if (isNaN(objValue.year))
{
results.push(new ValidationResult(
true, yearProp, "wrongYear",
validator.wrongYearError));
}
else
{
yearRequired = true;
}
var dayMissing:Boolean = (!objValue.day || objValue.day == "");
var dayInvalid:Boolean = dayMissing || isNaN(objValue.day);
var dayWrong:Boolean = !dayMissing && isNaN(objValue.day);
var dayOptional:Boolean = yearRequired && monthRequired;
// If the validator is required and there is no day specified
if (validator.required && dayMissing)
{
results.push(new ValidationResult(
true, dayProp, "requiredField",
validator.requiredFieldError));
}
else if (!dayInvalid) // The day is valid (a number).
{
dayRequired = true;
}
else if (!dayOptional || dayWrong) // Day is not optional and is NaN.
{
results.push(new ValidationResult(
true, dayProp, "wrongDay",
validator.wrongDayError));
}
dateObj.month = objValue.month ? String(objValue.month) : "";
dateObj.day = objValue.day ? String(objValue.day) : "";
dateObj.year = objValue.year ? String(objValue.year) : "";
}
else
{
var result:ValidationResult = DateValidator.validateFormatString(
validator, inputFormat, baseField);
if (result != null)
{
results.push(result);
return results;
}
else
{
var len:Number = stringValue.length;
if (len > inputFormat.length ||
len + 2 < inputFormat.length)
{
results.push(new ValidationResult(
true, baseField, "wrongLength",
validator.wrongLengthError + " " + inputFormat));
return results;
}
var j:int = 0;
n = inputFormat.length;
for (i = 0; i < n; i++)
{
temp = "" + stringValue.substring(j, j + 1);
var mask:String = "" + inputFormat.substring(i, i + 1);
// Check each character to see if it is allowed.
if (validInput.indexOf(temp) == -1)
{
results.push(new ValidationResult(
true, baseField, "invalidChar",
validator.invalidCharError));
return results;
}
if (mask == "m" || mask == "M")
{
monthRequired = true;
if (isNaN(Number(temp)))
advanceValueCounter = false;
else
dateObj.month += temp;
}
else if (mask == "d" || mask == "D")
{
dayRequired = true;
if (isNaN(Number(temp)))
advanceValueCounter = false;
else
dateObj.day += temp;
}
else if (mask == "y" || mask == "Y")
{
yearRequired = true;
if (isNaN(Number(temp)))
{
results.push(new ValidationResult(
true, baseField, "wrongLength",
validator.wrongLengthError + " " +
inputFormat));
return results;
}
else
{
dateObj.year += temp;
}
}
else if (allowedFormatChars.indexOf(temp) == -1)
{
results.push(new ValidationResult(
true, baseField, "invalidChar",
validator.invalidCharError));
return results;
}
if (advanceValueCounter)
j++;
advanceValueCounter = true;
}
if ((monthRequired && dateObj.month == "") ||
(dayRequired && dateObj.day == "") ||
(yearRequired && dateObj.year == "") ||
(j != len))
{
results.push(new ValidationResult(
true, baseField, "wrongLength",
validator.wrongLengthError + " " +
inputFormat));
return results;
}
}
}
// Now, validate the sub-elements, which may have been set directly.
n = dateObj.month.length;
for (i = 0; i < n; i++)
{
temp = "" + dateObj.month.substring(i, i + 1);
if (DECIMAL_DIGITS.indexOf(temp) == -1)
{
results.push(new ValidationResult(
true, monthProp, "invalidChar",
validator.invalidCharError));
}
}
n = dateObj.day.length;
for (i = 0; i < n; i++)
{
temp = "" + dateObj.day.substring(i, i + 1);
if (DECIMAL_DIGITS.indexOf(temp) == -1)
{
results.push(new ValidationResult(
true, dayProp, "invalidChar",
validator.invalidCharError));
}
}
n = dateObj.year.length;
for (i = 0; i < n; i++)
{
temp = "" + dateObj.year.substring(i, i + 1);
if (DECIMAL_DIGITS.indexOf(temp) == -1)
{
results.push(new ValidationResult(
true, yearProp, "invalidChar",
validator.invalidCharError));
}
}
if (results.length > 0)
return results;
var monthNum:Number = Number(dateObj.month);
var dayNum:Number = Number(dateObj.day);
var yearNum:Number = Number(dateObj.year).valueOf();
if (monthNum > 12 || monthNum < 1)
{
results.push(new ValidationResult(
true, monthProp, "wrongMonth",
validator.wrongMonthError));
return results;
}
var maxDay:Number = 31;
if (monthNum == 4 || monthNum == 6 ||
monthNum == 9 || monthNum == 11)
{
maxDay = 30;
}
else if (monthNum == 2)
{
if (yearNum % 4 > 0)
maxDay = 28;
else if (yearNum % 100 == 0 && yearNum % 400 > 0)
maxDay = 28;
else
maxDay = 29;
}
if (dayRequired && (dayNum > maxDay || dayNum < 1))
{
results.push(new ValidationResult(
true, dayProp, "wrongDay",
validator.wrongDayError));
return results;
}
if (yearRequired && (yearNum > 9999 || yearNum < 0))
{
results.push(new ValidationResult(
true, yearProp, "wrongYear",
validator.wrongYearError));
return results;
}
return results;
}
Em Project > Properties > Flex Compiler > Additional compiler arguments normalmente vc terá:
locale en_US vc terá q colocar locale=en_US,es_ES sem espaços e ter a pasta es_ES na pasta do sdk e informar em runtime qual usar.
Mais informações em:
http://fabiophx.blogspot.com.br/2010/06/locale-ptbr.html
Espero ter ajudado.
[]s
Fabio da Silva
http://fabiophx.blogspot.com.br/