Skip to content

Commit 9281efb

Browse files
committed
messages lang
1 parent 411df4d commit 9281efb

File tree

5 files changed

+101
-9
lines changed

5 files changed

+101
-9
lines changed

Ajax/Semantic.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
use Ajax\semantic\traits\SemanticHtmlCollectionsTrait;
1919
use Ajax\semantic\traits\SemanticHtmlModulesTrait;
2020
use Ajax\semantic\traits\SemanticHtmlViewsTrait;
21+
use function Composer\Autoload\includeFile;
2122

2223
class Semantic extends BaseGui {
2324
use SemanticComponentsTrait,SemanticHtmlElementsTrait,SemanticHtmlCollectionsTrait,
2425
SemanticHtmlModulesTrait,SemanticHtmlViewsTrait;
2526

27+
private $language;
28+
2629
public function __construct($autoCompile=true) {
2730
parent::__construct($autoCompile=true);
2831
}
@@ -106,4 +109,15 @@ public function htmlAccordionMenu($identifier, $items=array()) {
106109
public function htmlSticky($identifier, $content=array()) {
107110
return $this->addHtmlComponent(new HtmlSticky($identifier, $content));
108111
}
112+
113+
public function setLanguage($language){
114+
if($language!==$this->language){
115+
$file=\realpath(dirname(__FILE__)."/semantic/components/validation/languages/".$language.".js");
116+
if(\file_exists($file)){
117+
$script=\file_get_contents($file);
118+
$this->js->exec($script,true);
119+
$this->language=$language;
120+
}
121+
}
122+
}
109123
}

Ajax/semantic/components/validation/Rule.php

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,68 @@ public function jsonSerialize() {
6262
return $result;
6363
}
6464

65-
public static function match($name,$prompt=null){
65+
public static function match($name,$prompt=NULL){
6666
return new Rule("match[".$name."]",$prompt);
6767
}
6868

69-
public static function integer($min=0,$max=100,$prompt=null){
69+
public static function integer($min=0,$max=100,$prompt=NULL){
7070
return new Rule("integer[{$min}..{$max}]",$prompt);
7171
}
7272

73-
public static function decimal($prompt=null){
74-
return new Rule("decimal]",$prompt);
73+
public static function decimal($prompt=NULL){
74+
return new Rule("decimal",$prompt);
7575
}
7676

77-
public static function number($prompt=null){
77+
public static function number($prompt=NULL){
7878
return new Rule("number",$prompt);
7979
}
8080

81+
public static function is($value,$prompt=NULL){
82+
return new Rule("is[".$value."]",$prompt);
83+
}
84+
85+
public static function isExactly($value,$prompt=NULL){
86+
return new Rule("isExactly[".$value."]",$prompt);
87+
}
88+
89+
public static function not($value,$prompt=NULL){
90+
return new Rule("not[".$value."]",$prompt);
91+
}
92+
93+
public static function notExactly($value,$prompt=NULL){
94+
return new Rule("notExactly[".$value."]",$prompt);
95+
}
96+
97+
public static function contains($value,$prompt=NULL){
98+
return new Rule("contains[".$value."]",$prompt);
99+
}
100+
101+
public static function containsExactly($value,$prompt=NULL){
102+
return new Rule("containsExactly[".$value."]",$prompt);
103+
}
104+
105+
public static function doesntContain($value,$prompt=NULL){
106+
return new Rule("doesntContain[".$value."]",$prompt);
107+
}
108+
109+
public static function doesntContainExactly($value,$prompt=NULL){
110+
return new Rule("doesntContainExactly[".$value."]",$prompt);
111+
}
112+
113+
public static function minCount($value,$prompt=NULL){
114+
return new Rule("minCount[".$value."]",$prompt);
115+
}
116+
117+
public static function maxCount($value,$prompt=NULL){
118+
return new Rule("maxCount[".$value."]",$prompt);
119+
}
120+
121+
public static function exactCount($value,$prompt=NULL){
122+
return new Rule("exactCount[".$value."]",$prompt);
123+
}
124+
125+
public static function email($prompt=NULL){
126+
return new Rule("email",$prompt);
127+
}
128+
81129
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
$.fn.form.settings.prompt= {
2+
empty : '{name} doit avoir une valeur',
3+
checked : '{name} doit être coché',
4+
email : '{name} must be a valid e-mail',
5+
url : '{name} must be a valid url',
6+
regExp : '{name} is not formatted correctly',
7+
integer : '{name} must be an integer',
8+
decimal : '{name} must be a decimal number',
9+
number : '{name} must be set to a number',
10+
is : '{name} must be \'{ruleValue}\'',
11+
isExactly : '{name} must be exactly \'{ruleValue}\'',
12+
not : '{name} cannot be set to \'{ruleValue}\'',
13+
notExactly : '{name} cannot be set to exactly \'{ruleValue}\'',
14+
contain : '{name} cannot contain \'{ruleValue}\'',
15+
containExactly : '{name} cannot contain exactly \'{ruleValue}\'',
16+
doesntContain : '{name} must contain \'{ruleValue}\'',
17+
doesntContainExactly : '{name} must contain exactly \'{ruleValue}\'',
18+
minLength : '{name} must be at least {ruleValue} characters',
19+
length : '{name} must be at least {ruleValue} characters',
20+
exactLength : '{name} must be exactly {ruleValue} characters',
21+
maxLength : '{name} cannot be longer than {ruleValue} characters',
22+
match : '{name} must match {ruleValue} field',
23+
different : '{name} must have a different value than {ruleValue} field',
24+
creditCard : '{name} must be a valid credit card number',
25+
minCount : '{name} must have at least {ruleValue} choices',
26+
exactCount : '{name} must have exactly {ruleValue} choices',
27+
maxCount : '{name} must have {ruleValue} or less choices'
28+
};

Ajax/semantic/html/collections/form/HtmlForm.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,18 @@ public function addMessage($identifier, $content, $header=NULL, $icon=NULL, $typ
146146
}
147147

148148
public function run(JsUtils $js) {
149-
$hasValidation=false;
150-
$compo=$js->semantic()->form("#".$this->identifier);
149+
$compo=NULL;
151150
foreach ($this->_fields as $field){
152151
$validation=$field->getValidation();
153152
if(isset($validation)){
153+
if(isset($compo)===false){
154+
$compo=$js->semantic()->form("#".$this->identifier);
155+
}
154156
$validation->setIdentifier($field->getField()->getIdentifier());
155157
$compo->addFieldValidation($validation);
156-
$hasValidation=true;
157158
}
158159
}
159-
if($hasValidation===false){
160+
if(isset($compo)===false){
160161
return parent::run($js);
161162
}
162163
$compo->addParams($this->_validationParams);

Ajax/semantic/html/collections/form/HtmlFormField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function __construct($identifier, $field,$label=NULL) {
1919
if(isset($label))
2020
$this->setLabel($label);
2121
$this->setField($field);
22+
$this->_validation=NULL;
2223
}
2324

2425
public function addPointingLabel($label,$pointing=Direction::NONE){

0 commit comments

Comments
 (0)