You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9256 lines
315 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.form.Field
  17. * @extends Ext.BoxComponent
  18. * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
  19. * @constructor
  20. * Creates a new Field
  21. * @param {Object} config Configuration options
  22. * @xtype field
  23. */
  24. Ext.form.Field = Ext.extend(Ext.BoxComponent, {
  25. /**
  26. * <p>The label Element associated with this Field. <b>Only available after this Field has been rendered by a
  27. * {@link form Ext.layout.FormLayout} layout manager.</b></p>
  28. * @type Ext.Element
  29. * @property label
  30. */
  31. /**
  32. * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password, file (defaults
  33. * to 'text'). The types 'file' and 'password' must be used to render those field types currently -- there are
  34. * no separate Ext components for those. Note that if you use <tt>inputType:'file'</tt>, {@link #emptyText}
  35. * is not supported and should be avoided.
  36. */
  37. /**
  38. * @cfg {Number} tabIndex The tabIndex for this field. Note this only applies to fields that are rendered,
  39. * not those which are built via applyTo (defaults to undefined).
  40. */
  41. /**
  42. * @cfg {Mixed} value A value to initialize this field with (defaults to undefined).
  43. */
  44. /**
  45. * @cfg {String} name The field's HTML name attribute (defaults to '').
  46. * <b>Note</b>: this property must be set if this field is to be automatically included with
  47. * {@link Ext.form.BasicForm#submit form submit()}.
  48. */
  49. /**
  50. * @cfg {String} cls A custom CSS class to apply to the field's underlying element (defaults to '').
  51. */
  52. /**
  53. * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to 'x-form-invalid')
  54. */
  55. invalidClass : 'x-form-invalid',
  56. /**
  57. * @cfg {String} invalidText The error text to use when marking a field invalid and no message is provided
  58. * (defaults to 'The value in this field is invalid')
  59. */
  60. invalidText : 'The value in this field is invalid',
  61. /**
  62. * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to 'x-form-focus')
  63. */
  64. focusClass : 'x-form-focus',
  65. /**
  66. * @cfg {Boolean} preventMark
  67. * <tt>true</tt> to disable {@link #markInvalid marking the field invalid}.
  68. * Defaults to <tt>false</tt>.
  69. */
  70. /**
  71. * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
  72. automatic validation (defaults to 'keyup').
  73. */
  74. validationEvent : 'keyup',
  75. /**
  76. * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
  77. */
  78. validateOnBlur : true,
  79. /**
  80. * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation
  81. * is initiated (defaults to 250)
  82. */
  83. validationDelay : 250,
  84. /**
  85. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
  86. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  87. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  88. * <pre><code>{tag: 'input', type: 'text', size: '20', autocomplete: 'off'}</code></pre>
  89. */
  90. defaultAutoCreate : {tag: 'input', type: 'text', size: '20', autocomplete: 'off'},
  91. /**
  92. * @cfg {String} fieldClass The default CSS class for the field (defaults to 'x-form-field')
  93. */
  94. fieldClass : 'x-form-field',
  95. /**
  96. * @cfg {String} msgTarget <p>The location where the message text set through {@link #markInvalid} should display.
  97. * Must be one of the following values:</p>
  98. * <div class="mdetail-params"><ul>
  99. * <li><code>qtip</code> Display a quick tip containing the message when the user hovers over the field. This is the default.
  100. * <div class="subdesc"><b>{@link Ext.QuickTips#init Ext.QuickTips.init} must have been called for this setting to work.</b></div</li>
  101. * <li><code>title</code> Display the message in a default browser title attribute popup.</li>
  102. * <li><code>under</code> Add a block div beneath the field containing the error message.</li>
  103. * <li><code>side</code> Add an error icon to the right of the field, displaying the message in a popup on hover.</li>
  104. * <li><code>[element id]</code> Add the error message directly to the innerHTML of the specified element.</li>
  105. * </ul></div>
  106. */
  107. msgTarget : 'qtip',
  108. /**
  109. * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field
  110. * (defaults to 'normal').
  111. */
  112. msgFx : 'normal',
  113. /**
  114. * @cfg {Boolean} readOnly <tt>true</tt> to mark the field as readOnly in HTML
  115. * (defaults to <tt>false</tt>).
  116. * <br><p><b>Note</b>: this only sets the element's readOnly DOM attribute.
  117. * Setting <code>readOnly=true</code>, for example, will not disable triggering a
  118. * ComboBox or DateField; it gives you the option of forcing the user to choose
  119. * via the trigger without typing in the text box. To hide the trigger use
  120. * <code>{@link Ext.form.TriggerField#hideTrigger hideTrigger}</code>.</p>
  121. */
  122. readOnly : false,
  123. /**
  124. * @cfg {Boolean} disabled True to disable the field (defaults to false).
  125. * <p>Be aware that conformant with the <a href="http://www.w3.org/TR/html401/interact/forms.html#h-17.12.1">HTML specification</a>,
  126. * disabled Fields will not be {@link Ext.form.BasicForm#submit submitted}.</p>
  127. */
  128. disabled : false,
  129. /**
  130. * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
  131. * Defaults to <tt>true</tt>.
  132. */
  133. submitValue: true,
  134. // private
  135. isFormField : true,
  136. // private
  137. msgDisplay: '',
  138. // private
  139. hasFocus : false,
  140. // private
  141. initComponent : function(){
  142. Ext.form.Field.superclass.initComponent.call(this);
  143. this.addEvents(
  144. /**
  145. * @event focus
  146. * Fires when this field receives input focus.
  147. * @param {Ext.form.Field} this
  148. */
  149. 'focus',
  150. /**
  151. * @event blur
  152. * Fires when this field loses input focus.
  153. * @param {Ext.form.Field} this
  154. */
  155. 'blur',
  156. /**
  157. * @event specialkey
  158. * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed.
  159. * To handle other keys see {@link Ext.Panel#keys} or {@link Ext.KeyMap}.
  160. * You can check {@link Ext.EventObject#getKey} to determine which key was pressed.
  161. * For example: <pre><code>
  162. var form = new Ext.form.FormPanel({
  163. ...
  164. items: [{
  165. fieldLabel: 'Field 1',
  166. name: 'field1',
  167. allowBlank: false
  168. },{
  169. fieldLabel: 'Field 2',
  170. name: 'field2',
  171. listeners: {
  172. specialkey: function(field, e){
  173. // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
  174. // e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
  175. if (e.{@link Ext.EventObject#getKey getKey()} == e.ENTER) {
  176. var form = field.ownerCt.getForm();
  177. form.submit();
  178. }
  179. }
  180. }
  181. }
  182. ],
  183. ...
  184. });
  185. * </code></pre>
  186. * @param {Ext.form.Field} this
  187. * @param {Ext.EventObject} e The event object
  188. */
  189. 'specialkey',
  190. /**
  191. * @event change
  192. * Fires just before the field blurs if the field value has changed.
  193. * @param {Ext.form.Field} this
  194. * @param {Mixed} newValue The new value
  195. * @param {Mixed} oldValue The original value
  196. */
  197. 'change',
  198. /**
  199. * @event invalid
  200. * Fires after the field has been marked as invalid.
  201. * @param {Ext.form.Field} this
  202. * @param {String} msg The validation message
  203. */
  204. 'invalid',
  205. /**
  206. * @event valid
  207. * Fires after the field has been validated with no errors.
  208. * @param {Ext.form.Field} this
  209. */
  210. 'valid'
  211. );
  212. },
  213. /**
  214. * Returns the {@link Ext.form.Field#name name} or {@link Ext.form.ComboBox#hiddenName hiddenName}
  215. * attribute of the field if available.
  216. * @return {String} name The field {@link Ext.form.Field#name name} or {@link Ext.form.ComboBox#hiddenName hiddenName}
  217. */
  218. getName : function(){
  219. return this.rendered && this.el.dom.name ? this.el.dom.name : this.name || this.id || '';
  220. },
  221. // private
  222. onRender : function(ct, position){
  223. if(!this.el){
  224. var cfg = this.getAutoCreate();
  225. if(!cfg.name){
  226. cfg.name = this.name || this.id;
  227. }
  228. if(this.inputType){
  229. cfg.type = this.inputType;
  230. }
  231. this.autoEl = cfg;
  232. }
  233. Ext.form.Field.superclass.onRender.call(this, ct, position);
  234. if(this.submitValue === false){
  235. this.el.dom.removeAttribute('name');
  236. }
  237. var type = this.el.dom.type;
  238. if(type){
  239. if(type == 'password'){
  240. type = 'text';
  241. }
  242. this.el.addClass('x-form-'+type);
  243. }
  244. if(this.readOnly){
  245. this.setReadOnly(true);
  246. }
  247. if(this.tabIndex !== undefined){
  248. this.el.dom.setAttribute('tabIndex', this.tabIndex);
  249. }
  250. this.el.addClass([this.fieldClass, this.cls]);
  251. },
  252. // private
  253. getItemCt : function(){
  254. return this.itemCt;
  255. },
  256. // private
  257. initValue : function(){
  258. if(this.value !== undefined){
  259. this.setValue(this.value);
  260. }else if(!Ext.isEmpty(this.el.dom.value) && this.el.dom.value != this.emptyText){
  261. this.setValue(this.el.dom.value);
  262. }
  263. /**
  264. * The original value of the field as configured in the {@link #value} configuration, or
  265. * as loaded by the last form load operation if the form's {@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  266. * setting is <code>true</code>.
  267. * @type mixed
  268. * @property originalValue
  269. */
  270. this.originalValue = this.getValue();
  271. },
  272. /**
  273. * <p>Returns true if the value of this Field has been changed from its original value.
  274. * Will return false if the field is disabled or has not been rendered yet.</p>
  275. * <p>Note that if the owning {@link Ext.form.BasicForm form} was configured with
  276. * {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  277. * then the <i>original value</i> is updated when the values are loaded by
  278. * {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#setValues setValues}.</p>
  279. * @return {Boolean} True if this field has been changed from its original value (and
  280. * is not disabled), false otherwise.
  281. */
  282. isDirty : function() {
  283. if(this.disabled || !this.rendered) {
  284. return false;
  285. }
  286. return String(this.getValue()) !== String(this.originalValue);
  287. },
  288. /**
  289. * Sets the read only state of this field.
  290. * @param {Boolean} readOnly Whether the field should be read only.
  291. */
  292. setReadOnly : function(readOnly){
  293. if(this.rendered){
  294. this.el.dom.readOnly = readOnly;
  295. }
  296. this.readOnly = readOnly;
  297. },
  298. // private
  299. afterRender : function(){
  300. Ext.form.Field.superclass.afterRender.call(this);
  301. this.initEvents();
  302. this.initValue();
  303. },
  304. // private
  305. fireKey : function(e){
  306. if(e.isSpecialKey()){
  307. this.fireEvent('specialkey', this, e);
  308. }
  309. },
  310. /**
  311. * Resets the current field value to the originally loaded value and clears any validation messages.
  312. * See {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  313. */
  314. reset : function(){
  315. this.setValue(this.originalValue);
  316. this.clearInvalid();
  317. },
  318. // private
  319. initEvents : function(){
  320. this.mon(this.el, Ext.EventManager.getKeyEvent(), this.fireKey, this);
  321. this.mon(this.el, 'focus', this.onFocus, this);
  322. // standardise buffer across all browsers + OS-es for consistent event order.
  323. // (the 10ms buffer for Editors fixes a weird FF/Win editor issue when changing OS window focus)
  324. this.mon(this.el, 'blur', this.onBlur, this, this.inEditor ? {buffer:10} : null);
  325. },
  326. // private
  327. preFocus: Ext.emptyFn,
  328. // private
  329. onFocus : function(){
  330. this.preFocus();
  331. if(this.focusClass){
  332. this.el.addClass(this.focusClass);
  333. }
  334. if(!this.hasFocus){
  335. this.hasFocus = true;
  336. /**
  337. * <p>The value that the Field had at the time it was last focused. This is the value that is passed
  338. * to the {@link #change} event which is fired if the value has been changed when the Field is blurred.</p>
  339. * <p><b>This will be undefined until the Field has been visited.</b> Compare {@link #originalValue}.</p>
  340. * @type mixed
  341. * @property startValue
  342. */
  343. this.startValue = this.getValue();
  344. this.fireEvent('focus', this);
  345. }
  346. },
  347. // private
  348. beforeBlur : Ext.emptyFn,
  349. // private
  350. onBlur : function(){
  351. this.beforeBlur();
  352. if(this.focusClass){
  353. this.el.removeClass(this.focusClass);
  354. }
  355. this.hasFocus = false;
  356. if(this.validationEvent !== false && (this.validateOnBlur || this.validationEvent == 'blur')){
  357. this.validate();
  358. }
  359. var v = this.getValue();
  360. if(String(v) !== String(this.startValue)){
  361. this.fireEvent('change', this, v, this.startValue);
  362. }
  363. this.fireEvent('blur', this);
  364. this.postBlur();
  365. },
  366. // private
  367. postBlur : Ext.emptyFn,
  368. /**
  369. * Returns whether or not the field value is currently valid by
  370. * {@link #validateValue validating} the {@link #processValue processed value}
  371. * of the field. <b>Note</b>: {@link #disabled} fields are ignored.
  372. * @param {Boolean} preventMark True to disable marking the field invalid
  373. * @return {Boolean} True if the value is valid, else false
  374. */
  375. isValid : function(preventMark){
  376. if(this.disabled){
  377. return true;
  378. }
  379. var restore = this.preventMark;
  380. this.preventMark = preventMark === true;
  381. var v = this.validateValue(this.processValue(this.getRawValue()), preventMark);
  382. this.preventMark = restore;
  383. return v;
  384. },
  385. /**
  386. * Validates the field value
  387. * @return {Boolean} True if the value is valid, else false
  388. */
  389. validate : function(){
  390. if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
  391. this.clearInvalid();
  392. return true;
  393. }
  394. return false;
  395. },
  396. /**
  397. * This method should only be overridden if necessary to prepare raw values
  398. * for validation (see {@link #validate} and {@link #isValid}). This method
  399. * is expected to return the processed value for the field which will
  400. * be used for validation (see validateValue method).
  401. * @param {Mixed} value
  402. */
  403. processValue : function(value){
  404. return value;
  405. },
  406. /**
  407. * Uses getErrors to build an array of validation errors. If any errors are found, markInvalid is called
  408. * with the first and false is returned, otherwise true is returned. Previously, subclasses were invited
  409. * to provide an implementation of this to process validations - from 3.2 onwards getErrors should be
  410. * overridden instead.
  411. * @param {Mixed} The current value of the field
  412. * @return {Boolean} True if all validations passed, false if one or more failed
  413. */
  414. validateValue : function(value) {
  415. //currently, we only show 1 error at a time for a field, so just use the first one
  416. var error = this.getErrors(value)[0];
  417. if (error == undefined) {
  418. return true;
  419. } else {
  420. this.markInvalid(error);
  421. return false;
  422. }
  423. },
  424. /**
  425. * Runs this field's validators and returns an array of error messages for any validation failures.
  426. * This is called internally during validation and would not usually need to be used manually.
  427. * Each subclass should override or augment the return value to provide their own errors
  428. * @return {Array} All error messages for this field
  429. */
  430. getErrors: function() {
  431. return [];
  432. },
  433. /**
  434. * Gets the active error message for this field.
  435. * @return {String} Returns the active error message on the field, if there is no error, an empty string is returned.
  436. */
  437. getActiveError : function(){
  438. return this.activeError || '';
  439. },
  440. /**
  441. * <p>Display an error message associated with this field, using {@link #msgTarget} to determine how to
  442. * display the message and applying {@link #invalidClass} to the field's UI element.</p>
  443. * <p><b>Note</b>: this method does not cause the Field's {@link #validate} method to return <code>false</code>
  444. * if the value does <i>pass</i> validation. So simply marking a Field as invalid will not prevent
  445. * submission of forms submitted with the {@link Ext.form.Action.Submit#clientValidation} option set.</p>
  446. * {@link #isValid invalid}.
  447. * @param {String} msg (optional) The validation message (defaults to {@link #invalidText})
  448. */
  449. markInvalid : function(msg){
  450. //don't set the error icon if we're not rendered or marking is prevented
  451. if (this.rendered && !this.preventMark) {
  452. msg = msg || this.invalidText;
  453. var mt = this.getMessageHandler();
  454. if(mt){
  455. mt.mark(this, msg);
  456. }else if(this.msgTarget){
  457. this.el.addClass(this.invalidClass);
  458. var t = Ext.getDom(this.msgTarget);
  459. if(t){
  460. t.innerHTML = msg;
  461. t.style.display = this.msgDisplay;
  462. }
  463. }
  464. }
  465. this.setActiveError(msg);
  466. },
  467. /**
  468. * Clear any invalid styles/messages for this field
  469. */
  470. clearInvalid : function(){
  471. //don't remove the error icon if we're not rendered or marking is prevented
  472. if (this.rendered && !this.preventMark) {
  473. this.el.removeClass(this.invalidClass);
  474. var mt = this.getMessageHandler();
  475. if(mt){
  476. mt.clear(this);
  477. }else if(this.msgTarget){
  478. this.el.removeClass(this.invalidClass);
  479. var t = Ext.getDom(this.msgTarget);
  480. if(t){
  481. t.innerHTML = '';
  482. t.style.display = 'none';
  483. }
  484. }
  485. }
  486. this.unsetActiveError();
  487. },
  488. /**
  489. * Sets the current activeError to the given string. Fires the 'invalid' event.
  490. * This does not set up the error icon, only sets the message and fires the event. To show the error icon,
  491. * use markInvalid instead, which calls this method internally
  492. * @param {String} msg The error message
  493. * @param {Boolean} suppressEvent True to suppress the 'invalid' event from being fired
  494. */
  495. setActiveError: function(msg, suppressEvent) {
  496. this.activeError = msg;
  497. if (suppressEvent !== true) this.fireEvent('invalid', this, msg);
  498. },
  499. /**
  500. * Clears the activeError and fires the 'valid' event. This is called internally by clearInvalid and would not
  501. * usually need to be called manually
  502. * @param {Boolean} suppressEvent True to suppress the 'invalid' event from being fired
  503. */
  504. unsetActiveError: function(suppressEvent) {
  505. delete this.activeError;
  506. if (suppressEvent !== true) this.fireEvent('valid', this);
  507. },
  508. // private
  509. getMessageHandler : function(){
  510. return Ext.form.MessageTargets[this.msgTarget];
  511. },
  512. // private
  513. getErrorCt : function(){
  514. return this.el.findParent('.x-form-element', 5, true) || // use form element wrap if available
  515. this.el.findParent('.x-form-field-wrap', 5, true); // else direct field wrap
  516. },
  517. // Alignment for 'under' target
  518. alignErrorEl : function(){
  519. this.errorEl.setWidth(this.getErrorCt().getWidth(true) - 20);
  520. },
  521. // Alignment for 'side' target
  522. alignErrorIcon : function(){
  523. this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
  524. },
  525. /**
  526. * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
  527. * @return {Mixed} value The field value
  528. */
  529. getRawValue : function(){
  530. var v = this.rendered ? this.el.getValue() : Ext.value(this.value, '');
  531. if(v === this.emptyText){
  532. v = '';
  533. }
  534. return v;
  535. },
  536. /**
  537. * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
  538. * @return {Mixed} value The field value
  539. */
  540. getValue : function(){
  541. if(!this.rendered) {
  542. return this.value;
  543. }
  544. var v = this.el.getValue();
  545. if(v === this.emptyText || v === undefined){
  546. v = '';
  547. }
  548. return v;
  549. },
  550. /**
  551. * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
  552. * @param {Mixed} value The value to set
  553. * @return {Mixed} value The field value that is set
  554. */
  555. setRawValue : function(v){
  556. return this.rendered ? (this.el.dom.value = (Ext.isEmpty(v) ? '' : v)) : '';
  557. },
  558. /**
  559. * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
  560. * @param {Mixed} value The value to set
  561. * @return {Ext.form.Field} this
  562. */
  563. setValue : function(v){
  564. this.value = v;
  565. if(this.rendered){
  566. this.el.dom.value = (Ext.isEmpty(v) ? '' : v);
  567. this.validate();
  568. }
  569. return this;
  570. },
  571. // private, does not work for all fields
  572. append : function(v){
  573. this.setValue([this.getValue(), v].join(''));
  574. }
  575. /**
  576. * @cfg {Boolean} autoWidth @hide
  577. */
  578. /**
  579. * @cfg {Boolean} autoHeight @hide
  580. */
  581. /**
  582. * @cfg {String} autoEl @hide
  583. */
  584. });
  585. Ext.form.MessageTargets = {
  586. 'qtip' : {
  587. mark: function(field, msg){
  588. field.el.addClass(field.invalidClass);
  589. field.el.dom.qtip = msg;
  590. field.el.dom.qclass = 'x-form-invalid-tip';
  591. if(Ext.QuickTips){ // fix for floating editors interacting with DND
  592. Ext.QuickTips.enable();
  593. }
  594. },
  595. clear: function(field){
  596. field.el.removeClass(field.invalidClass);
  597. field.el.dom.qtip = '';
  598. }
  599. },
  600. 'title' : {
  601. mark: function(field, msg){
  602. field.el.addClass(field.invalidClass);
  603. field.el.dom.title = msg;
  604. },
  605. clear: function(field){
  606. field.el.dom.title = '';
  607. }
  608. },
  609. 'under' : {
  610. mark: function(field, msg){
  611. field.el.addClass(field.invalidClass);
  612. if(!field.errorEl){
  613. var elp = field.getErrorCt();
  614. if(!elp){ // field has no container el
  615. field.el.dom.title = msg;
  616. return;
  617. }
  618. field.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
  619. field.on('resize', field.alignErrorEl, field);
  620. field.on('destroy', function(){
  621. Ext.destroy(this.errorEl);
  622. }, field);
  623. }
  624. field.alignErrorEl();
  625. field.errorEl.update(msg);
  626. Ext.form.Field.msgFx[field.msgFx].show(field.errorEl, field);
  627. },
  628. clear: function(field){
  629. field.el.removeClass(field.invalidClass);
  630. if(field.errorEl){
  631. Ext.form.Field.msgFx[field.msgFx].hide(field.errorEl, field);
  632. }else{
  633. field.el.dom.title = '';
  634. }
  635. }
  636. },
  637. 'side' : {
  638. mark: function(field, msg){
  639. field.el.addClass(field.invalidClass);
  640. if(!field.errorIcon){
  641. var elp = field.getErrorCt();
  642. // field has no container el
  643. if(!elp){
  644. field.el.dom.title = msg;
  645. return;
  646. }
  647. field.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
  648. if (field.ownerCt) {
  649. field.ownerCt.on('afterlayout', field.alignErrorIcon, field);
  650. field.ownerCt.on('expand', field.alignErrorIcon, field);
  651. }
  652. field.on('resize', field.alignErrorIcon, field);
  653. field.on('destroy', function(){
  654. Ext.destroy(this.errorIcon);
  655. }, field);
  656. }
  657. field.alignErrorIcon();
  658. field.errorIcon.dom.qtip = msg;
  659. field.errorIcon.dom.qclass = 'x-form-invalid-tip';
  660. field.errorIcon.show();
  661. },
  662. clear: function(field){
  663. field.el.removeClass(field.invalidClass);
  664. if(field.errorIcon){
  665. field.errorIcon.dom.qtip = '';
  666. field.errorIcon.hide();
  667. }else{
  668. field.el.dom.title = '';
  669. }
  670. }
  671. }
  672. };
  673. // anything other than normal should be considered experimental
  674. Ext.form.Field.msgFx = {
  675. normal : {
  676. show: function(msgEl, f){
  677. msgEl.setDisplayed('block');
  678. },
  679. hide : function(msgEl, f){
  680. msgEl.setDisplayed(false).update('');
  681. }
  682. },
  683. slide : {
  684. show: function(msgEl, f){
  685. msgEl.slideIn('t', {stopFx:true});
  686. },
  687. hide : function(msgEl, f){
  688. msgEl.slideOut('t', {stopFx:true,useDisplay:true});
  689. }
  690. },
  691. slideRight : {
  692. show: function(msgEl, f){
  693. msgEl.fixDisplay();
  694. msgEl.alignTo(f.el, 'tl-tr');
  695. msgEl.slideIn('l', {stopFx:true});
  696. },
  697. hide : function(msgEl, f){
  698. msgEl.slideOut('l', {stopFx:true,useDisplay:true});
  699. }
  700. }
  701. };
  702. Ext.reg('field', Ext.form.Field);
  703. /**
  704. * @class Ext.form.TextField
  705. * @extends Ext.form.Field
  706. * <p>Basic text field. Can be used as a direct replacement for traditional text inputs,
  707. * or as the base class for more sophisticated input controls (like {@link Ext.form.TextArea}
  708. * and {@link Ext.form.ComboBox}).</p>
  709. * <p><b><u>Validation</u></b></p>
  710. * <p>The validation procedure is described in the documentation for {@link #validateValue}.</p>
  711. * <p><b><u>Alter Validation Behavior</u></b></p>
  712. * <p>Validation behavior for each field can be configured:</p>
  713. * <div class="mdetail-params"><ul>
  714. * <li><code>{@link Ext.form.TextField#invalidText invalidText}</code> : the default validation message to
  715. * show if any validation step above does not provide a message when invalid</li>
  716. * <li><code>{@link Ext.form.TextField#maskRe maskRe}</code> : filter out keystrokes before any validation occurs</li>
  717. * <li><code>{@link Ext.form.TextField#stripCharsRe stripCharsRe}</code> : filter characters after being typed in,
  718. * but before being validated</li>
  719. * <li><code>{@link Ext.form.Field#invalidClass invalidClass}</code> : alternate style when invalid</li>
  720. * <li><code>{@link Ext.form.Field#validateOnBlur validateOnBlur}</code>,
  721. * <code>{@link Ext.form.Field#validationDelay validationDelay}</code>, and
  722. * <code>{@link Ext.form.Field#validationEvent validationEvent}</code> : modify how/when validation is triggered</li>
  723. * </ul></div>
  724. *
  725. * @constructor Creates a new TextField
  726. * @param {Object} config Configuration options
  727. *
  728. * @xtype textfield
  729. */
  730. Ext.form.TextField = Ext.extend(Ext.form.Field, {
  731. /**
  732. * @cfg {String} vtypeText A custom error message to display in place of the default message provided
  733. * for the <b><code>{@link #vtype}</code></b> currently set for this field (defaults to <tt>''</tt>). <b>Note</b>:
  734. * only applies if <b><code>{@link #vtype}</code></b> is set, else ignored.
  735. */
  736. /**
  737. * @cfg {RegExp} stripCharsRe A JavaScript RegExp object used to strip unwanted content from the value
  738. * before validation (defaults to <tt>null</tt>).
  739. */
  740. /**
  741. * @cfg {Boolean} grow <tt>true</tt> if this field should automatically grow and shrink to its content
  742. * (defaults to <tt>false</tt>)
  743. */
  744. grow : false,
  745. /**
  746. * @cfg {Number} growMin The minimum width to allow when <code><b>{@link #grow}</b> = true</code> (defaults
  747. * to <tt>30</tt>)
  748. */
  749. growMin : 30,
  750. /**
  751. * @cfg {Number} growMax The maximum width to allow when <code><b>{@link #grow}</b> = true</code> (defaults
  752. * to <tt>800</tt>)
  753. */
  754. growMax : 800,
  755. /**
  756. * @cfg {String} vtype A validation type name as defined in {@link Ext.form.VTypes} (defaults to <tt>null</tt>)
  757. */
  758. vtype : null,
  759. /**
  760. * @cfg {RegExp} maskRe An input mask regular expression that will be used to filter keystrokes that do
  761. * not match (defaults to <tt>null</tt>). The maskRe will not operate on any paste events.
  762. */
  763. maskRe : null,
  764. /**
  765. * @cfg {Boolean} disableKeyFilter Specify <tt>true</tt> to disable input keystroke filtering (defaults
  766. * to <tt>false</tt>)
  767. */
  768. disableKeyFilter : false,
  769. /**
  770. * @cfg {Boolean} allowBlank Specify <tt>false</tt> to validate that the value's length is > 0 (defaults to
  771. * <tt>true</tt>)
  772. */
  773. allowBlank : true,
  774. /**
  775. * @cfg {Number} minLength Minimum input field length required (defaults to <tt>0</tt>)
  776. */
  777. minLength : 0,
  778. /**
  779. * @cfg {Number} maxLength Maximum input field length allowed by validation (defaults to Number.MAX_VALUE).
  780. * This behavior is intended to provide instant feedback to the user by improving usability to allow pasting
  781. * and editing or overtyping and back tracking. To restrict the maximum number of characters that can be
  782. * entered into the field use <tt><b>{@link Ext.form.Field#autoCreate autoCreate}</b></tt> to add
  783. * any attributes you want to a field, for example:<pre><code>
  784. var myField = new Ext.form.NumberField({
  785. id: 'mobile',
  786. anchor:'90%',
  787. fieldLabel: 'Mobile',
  788. maxLength: 16, // for validation
  789. autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '10'}
  790. });
  791. </code></pre>
  792. */
  793. maxLength : Number.MAX_VALUE,
  794. /**
  795. * @cfg {String} minLengthText Error text to display if the <b><tt>{@link #minLength minimum length}</tt></b>
  796. * validation fails (defaults to <tt>'The minimum length for this field is {minLength}'</tt>)
  797. */
  798. minLengthText : 'The minimum length for this field is {0}',
  799. /**
  800. * @cfg {String} maxLengthText Error text to display if the <b><tt>{@link #maxLength maximum length}</tt></b>
  801. * validation fails (defaults to <tt>'The maximum length for this field is {maxLength}'</tt>)
  802. */
  803. maxLengthText : 'The maximum length for this field is {0}',
  804. /**
  805. * @cfg {Boolean} selectOnFocus <tt>true</tt> to automatically select any existing field text when the field
  806. * receives input focus (defaults to <tt>false</tt>)
  807. */
  808. selectOnFocus : false,
  809. /**
  810. * @cfg {String} blankText The error text to display if the <b><tt>{@link #allowBlank}</tt></b> validation
  811. * fails (defaults to <tt>'This field is required'</tt>)
  812. */
  813. blankText : 'This field is required',
  814. /**
  815. * @cfg {Function} validator
  816. * <p>A custom validation function to be called during field validation ({@link #validateValue})
  817. * (defaults to <tt>null</tt>). If specified, this function will be called first, allowing the
  818. * developer to override the default validation process.</p>
  819. * <br><p>This function will be passed the following Parameters:</p>
  820. * <div class="mdetail-params"><ul>
  821. * <li><code>value</code>: <i>Mixed</i>
  822. * <div class="sub-desc">The current field value</div></li>
  823. * </ul></div>
  824. * <br><p>This function is to Return:</p>
  825. * <div class="mdetail-params"><ul>
  826. * <li><code>true</code>: <i>Boolean</i>
  827. * <div class="sub-desc"><code>true</code> if the value is valid</div></li>
  828. * <li><code>msg</code>: <i>String</i>
  829. * <div class="sub-desc">An error message if the value is invalid</div></li>
  830. * </ul></div>
  831. */
  832. validator : null,
  833. /**
  834. * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation
  835. * (defaults to <tt>null</tt>). If the test fails, the field will be marked invalid using
  836. * <b><tt>{@link #regexText}</tt></b>.
  837. */
  838. regex : null,
  839. /**
  840. * @cfg {String} regexText The error text to display if <b><tt>{@link #regex}</tt></b> is used and the
  841. * test fails during validation (defaults to <tt>''</tt>)
  842. */
  843. regexText : '',
  844. /**
  845. * @cfg {String} emptyText The default text to place into an empty field (defaults to <tt>null</tt>).
  846. * <b>Note</b>: that this value will be submitted to the server if this field is enabled and configured
  847. * with a {@link #name}.
  848. */
  849. emptyText : null,
  850. /**
  851. * @cfg {String} emptyClass The CSS class to apply to an empty field to style the <b><tt>{@link #emptyText}</tt></b>
  852. * (defaults to <tt>'x-form-empty-field'</tt>). This class is automatically added and removed as needed
  853. * depending on the current field value.
  854. */
  855. emptyClass : 'x-form-empty-field',
  856. /**
  857. * @cfg {Boolean} enableKeyEvents <tt>true</tt> to enable the proxying of key events for the HTML input
  858. * field (defaults to <tt>false</tt>)
  859. */
  860. initComponent : function(){
  861. Ext.form.TextField.superclass.initComponent.call(this);
  862. this.addEvents(
  863. /**
  864. * @event autosize
  865. * Fires when the <tt><b>{@link #autoSize}</b></tt> function is triggered. The field may or
  866. * may not have actually changed size according to the default logic, but this event provides
  867. * a hook for the developer to apply additional logic at runtime to resize the field if needed.
  868. * @param {Ext.form.Field} this This text field
  869. * @param {Number} width The new field width
  870. */
  871. 'autosize',
  872. /**
  873. * @event keydown
  874. * Keydown input field event. This event only fires if <tt><b>{@link #enableKeyEvents}</b></tt>
  875. * is set to true.
  876. * @param {Ext.form.TextField} this This text field
  877. * @param {Ext.EventObject} e
  878. */
  879. 'keydown',
  880. /**
  881. * @event keyup
  882. * Keyup input field event. This event only fires if <tt><b>{@link #enableKeyEvents}</b></tt>
  883. * is set to true.
  884. * @param {Ext.form.TextField} this This text field
  885. * @param {Ext.EventObject} e
  886. */
  887. 'keyup',
  888. /**
  889. * @event keypress
  890. * Keypress input field event. This event only fires if <tt><b>{@link #enableKeyEvents}</b></tt>
  891. * is set to true.
  892. * @param {Ext.form.TextField} this This text field
  893. * @param {Ext.EventObject} e
  894. */
  895. 'keypress'
  896. );
  897. },
  898. // private
  899. initEvents : function(){
  900. Ext.form.TextField.superclass.initEvents.call(this);
  901. if(this.validationEvent == 'keyup'){
  902. this.validationTask = new Ext.util.DelayedTask(this.validate, this);
  903. this.mon(this.el, 'keyup', this.filterValidation, this);
  904. }
  905. else if(this.validationEvent !== false && this.validationEvent != 'blur'){
  906. this.mon(this.el, this.validationEvent, this.validate, this, {buffer: this.validationDelay});
  907. }
  908. if(this.selectOnFocus || this.emptyText){
  909. this.mon(this.el, 'mousedown', this.onMouseDown, this);
  910. if(this.emptyText){
  911. this.applyEmptyText();
  912. }
  913. }
  914. if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Ext.form.VTypes[this.vtype+'Mask']))){
  915. this.mon(this.el, 'keypress', this.filterKeys, this);
  916. }
  917. if(this.grow){
  918. this.mon(this.el, 'keyup', this.onKeyUpBuffered, this, {buffer: 50});
  919. this.mon(this.el, 'click', this.autoSize, this);
  920. }
  921. if(this.enableKeyEvents){
  922. this.mon(this.el, {
  923. scope: this,
  924. keyup: this.onKeyUp,
  925. keydown: this.onKeyDown,
  926. keypress: this.onKeyPress
  927. });
  928. }
  929. },
  930. onMouseDown: function(e){
  931. if(!this.hasFocus){
  932. this.mon(this.el, 'mouseup', Ext.emptyFn, this, { single: true, preventDefault: true });
  933. }
  934. },
  935. processValue : function(value){
  936. if(this.stripCharsRe){
  937. var newValue = value.replace(this.stripCharsRe, '');
  938. if(newValue !== value){
  939. this.setRawValue(newValue);
  940. return newValue;
  941. }
  942. }
  943. return value;
  944. },
  945. filterValidation : function(e){
  946. if(!e.isNavKeyPress()){
  947. this.validationTask.delay(this.validationDelay);
  948. }
  949. },
  950. //private
  951. onDisable: function(){
  952. Ext.form.TextField.superclass.onDisable.call(this);
  953. if(Ext.isIE){
  954. this.el.dom.unselectable = 'on';
  955. }
  956. },
  957. //private
  958. onEnable: function(){
  959. Ext.form.TextField.superclass.onEnable.call(this);
  960. if(Ext.isIE){
  961. this.el.dom.unselectable = '';
  962. }
  963. },
  964. // private
  965. onKeyUpBuffered : function(e){
  966. if(this.doAutoSize(e)){
  967. this.autoSize();
  968. }
  969. },
  970. // private
  971. doAutoSize : function(e){
  972. return !e.isNavKeyPress();
  973. },
  974. // private
  975. onKeyUp : function(e){
  976. this.fireEvent('keyup', this, e);
  977. },
  978. // private
  979. onKeyDown : function(e){
  980. this.fireEvent('keydown', this, e);
  981. },
  982. // private
  983. onKeyPress : function(e){
  984. this.fireEvent('keypress', this, e);
  985. },
  986. /**
  987. * Resets the current field value to the originally-loaded value and clears any validation messages.
  988. * Also adds <tt><b>{@link #emptyText}</b></tt> and <tt><b>{@link #emptyClass}</b></tt> if the
  989. * original value was blank.
  990. */
  991. reset : function(){
  992. Ext.form.TextField.superclass.reset.call(this);
  993. this.applyEmptyText();
  994. },
  995. applyEmptyText : function(){
  996. if(this.rendered && this.emptyText && this.getRawValue().length < 1 && !this.hasFocus){
  997. this.setRawValue(this.emptyText);
  998. this.el.addClass(this.emptyClass);
  999. }
  1000. },
  1001. // private
  1002. preFocus : function(){
  1003. var el = this.el,
  1004. isEmpty;
  1005. if(this.emptyText){
  1006. if(el.dom.value == this.emptyText){
  1007. this.setRawValue('');
  1008. isEmpty = true;
  1009. }
  1010. el.removeClass(this.emptyClass);
  1011. }
  1012. if(this.selectOnFocus || isEmpty){
  1013. el.dom.select();
  1014. }
  1015. },
  1016. // private
  1017. postBlur : function(){
  1018. this.applyEmptyText();
  1019. },
  1020. // private
  1021. filterKeys : function(e){
  1022. if(e.ctrlKey){
  1023. return;
  1024. }
  1025. var k = e.getKey();
  1026. if(Ext.isGecko && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
  1027. return;
  1028. }
  1029. var cc = String.fromCharCode(e.getCharCode());
  1030. if(!Ext.isGecko && e.isSpecialKey() && !cc){
  1031. return;
  1032. }
  1033. if(!this.maskRe.test(cc)){
  1034. e.stopEvent();
  1035. }
  1036. },
  1037. setValue : function(v){
  1038. if(this.emptyText && this.el && !Ext.isEmpty(v)){
  1039. this.el.removeClass(this.emptyClass);
  1040. }
  1041. Ext.form.TextField.superclass.setValue.apply(this, arguments);
  1042. this.applyEmptyText();
  1043. this.autoSize();
  1044. return this;
  1045. },
  1046. /**
  1047. * <p>Validates a value according to the field's validation rules and returns an array of errors
  1048. * for any failing validations. Validation rules are processed in the following order:</p>
  1049. * <div class="mdetail-params"><ul>
  1050. *
  1051. * <li><b>1. Field specific validator</b>
  1052. * <div class="sub-desc">
  1053. * <p>A validator offers a way to customize and reuse a validation specification.
  1054. * If a field is configured with a <code>{@link #validator}</code>
  1055. * function, it will be passed the current field value. The <code>{@link #validator}</code>
  1056. * function is expected to return either:
  1057. * <div class="mdetail-params"><ul>
  1058. * <li>Boolean <tt>true</tt> if the value is valid (validation continues).</li>
  1059. * <li>a String to represent the invalid message if invalid (validation halts).</li>
  1060. * </ul></div>
  1061. * </div></li>
  1062. *
  1063. * <li><b>2. Basic Validation</b>
  1064. * <div class="sub-desc">
  1065. * <p>If the <code>{@link #validator}</code> has not halted validation,
  1066. * basic validation proceeds as follows:</p>
  1067. *
  1068. * <div class="mdetail-params"><ul>
  1069. *
  1070. * <li><code>{@link #allowBlank}</code> : (Invalid message =
  1071. * <code>{@link #emptyText}</code>)<div class="sub-desc">
  1072. * Depending on the configuration of <code>{@link #allowBlank}</code>, a
  1073. * blank field will cause validation to halt at this step and return
  1074. * Boolean true or false accordingly.
  1075. * </div></li>
  1076. *
  1077. * <li><code>{@link #minLength}</code> : (Invalid message =
  1078. * <code>{@link #minLengthText}</code>)<div class="sub-desc">
  1079. * If the passed value does not satisfy the <code>{@link #minLength}</code>
  1080. * specified, validation halts.
  1081. * </div></li>
  1082. *
  1083. * <li><code>{@link #maxLength}</code> : (Invalid message =
  1084. * <code>{@link #maxLengthText}</code>)<div class="sub-desc">
  1085. * If the passed value does not satisfy the <code>{@link #maxLength}</code>
  1086. * specified, validation halts.
  1087. * </div></li>
  1088. *
  1089. * </ul></div>
  1090. * </div></li>
  1091. *
  1092. * <li><b>3. Preconfigured Validation Types (VTypes)</b>
  1093. * <div class="sub-desc">
  1094. * <p>If none of the prior validation steps halts validation, a field
  1095. * configured with a <code>{@link #vtype}</code> will utilize the
  1096. * corresponding {@link Ext.form.VTypes VTypes} validation function.
  1097. * If invalid, either the field's <code>{@link #vtypeText}</code> or
  1098. * the VTypes vtype Text property will be used for the invalid message.
  1099. * Keystrokes on the field will be filtered according to the VTypes
  1100. * vtype Mask property.</p>
  1101. * </div></li>
  1102. *
  1103. * <li><b>4. Field specific regex test</b>
  1104. * <div class="sub-desc">
  1105. * <p>If none of the prior validation steps halts validation, a field's
  1106. * configured <code>{@link #regex}</code> test will be processed.
  1107. * The invalid message for this test is configured with
  1108. * <code>{@link #regexText}</code>.</p>
  1109. * </div></li>
  1110. *
  1111. * @param {Mixed} value The value to validate. The processed raw value will be used if nothing is passed
  1112. * @return {Array} Array of any validation errors
  1113. */
  1114. getErrors: function(value) {
  1115. var errors = Ext.form.TextField.superclass.getErrors.apply(this, arguments);
  1116. value = Ext.isDefined(value) ? value : this.processValue(this.getRawValue());
  1117. if (Ext.isFunction(this.validator)) {
  1118. var msg = this.validator(value);
  1119. if (msg !== true) {
  1120. errors.push(msg);
  1121. }
  1122. }
  1123. if (value.length < 1 || value === this.emptyText) {
  1124. if (this.allowBlank) {
  1125. //if value is blank and allowBlank is true, there cannot be any additional errors
  1126. return errors;
  1127. } else {
  1128. errors.push(this.blankText);
  1129. }
  1130. }
  1131. if (!this.allowBlank && (value.length < 1 || value === this.emptyText)) { // if it's blank
  1132. errors.push(this.blankText);
  1133. }
  1134. if (value.length < this.minLength) {
  1135. errors.push(String.format(this.minLengthText, this.minLength));
  1136. }
  1137. if (value.length > this.maxLength) {
  1138. errors.push(String.format(this.maxLengthText, this.maxLength));
  1139. }
  1140. if (this.vtype) {
  1141. var vt = Ext.form.VTypes;
  1142. if(!vt[this.vtype](value, this)){
  1143. errors.push(this.vtypeText || vt[this.vtype +'Text']);
  1144. }
  1145. }
  1146. if (this.regex && !this.regex.test(value)) {
  1147. errors.push(this.regexText);
  1148. }
  1149. return errors;
  1150. },
  1151. /**
  1152. * Selects text in this field
  1153. * @param {Number} start (optional) The index where the selection should start (defaults to 0)
  1154. * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
  1155. */
  1156. selectText : function(start, end){
  1157. var v = this.getRawValue();
  1158. var doFocus = false;
  1159. if(v.length > 0){
  1160. start = start === undefined ? 0 : start;
  1161. end = end === undefined ? v.length : end;
  1162. var d = this.el.dom;
  1163. if(d.setSelectionRange){
  1164. d.setSelectionRange(start, end);
  1165. }else if(d.createTextRange){
  1166. var range = d.createTextRange();
  1167. range.moveStart('character', start);
  1168. range.moveEnd('character', end-v.length);
  1169. range.select();
  1170. }
  1171. doFocus = Ext.isGecko || Ext.isOpera;
  1172. }else{
  1173. doFocus = true;
  1174. }
  1175. if(doFocus){
  1176. this.focus();
  1177. }
  1178. },
  1179. /**
  1180. * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
  1181. * This only takes effect if <tt><b>{@link #grow}</b> = true</tt>, and fires the {@link #autosize} event.
  1182. */
  1183. autoSize : function(){
  1184. if(!this.grow || !this.rendered){
  1185. return;
  1186. }
  1187. if(!this.metrics){
  1188. this.metrics = Ext.util.TextMetrics.createInstance(this.el);
  1189. }
  1190. var el = this.el;
  1191. var v = el.dom.value;
  1192. var d = document.createElement('div');
  1193. d.appendChild(document.createTextNode(v));
  1194. v = d.innerHTML;
  1195. Ext.removeNode(d);
  1196. d = null;
  1197. v += '&#160;';
  1198. var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
  1199. this.el.setWidth(w);
  1200. this.fireEvent('autosize', this, w);
  1201. },
  1202. onDestroy: function(){
  1203. if(this.validationTask){
  1204. this.validationTask.cancel();
  1205. this.validationTask = null;
  1206. }
  1207. Ext.form.TextField.superclass.onDestroy.call(this);
  1208. }
  1209. });
  1210. Ext.reg('textfield', Ext.form.TextField);
  1211. /**
  1212. * @class Ext.form.TriggerField
  1213. * @extends Ext.form.TextField
  1214. * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
  1215. * The trigger has no default action, so you must assign a function to implement the trigger click handler by
  1216. * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
  1217. * for which you can provide a custom implementation. For example:
  1218. * <pre><code>
  1219. var trigger = new Ext.form.TriggerField();
  1220. trigger.onTriggerClick = myTriggerFn;
  1221. trigger.applyToMarkup('my-field');
  1222. </code></pre>
  1223. *
  1224. * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
  1225. * {@link Ext.form.DateField} and {@link Ext.form.ComboBox} are perfect examples of this.
  1226. *
  1227. * @constructor
  1228. * Create a new TriggerField.
  1229. * @param {Object} config Configuration options (valid {@Ext.form.TextField} config options will also be applied
  1230. * to the base TextField)
  1231. * @xtype trigger
  1232. */
  1233. Ext.form.TriggerField = Ext.extend(Ext.form.TextField, {
  1234. /**
  1235. * @cfg {String} triggerClass
  1236. * An additional CSS class used to style the trigger button. The trigger will always get the
  1237. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  1238. */
  1239. /**
  1240. * @cfg {Mixed} triggerConfig
  1241. * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the
  1242. * trigger element for this Field. (Optional).</p>
  1243. * <p>Specify this when you need a customized element to act as the trigger button for a TriggerField.</p>
  1244. * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing, positioning
  1245. * and appearance of the trigger. Defaults to:</p>
  1246. * <pre><code>{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass}</code></pre>
  1247. */
  1248. /**
  1249. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
  1250. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  1251. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  1252. * <pre><code>{tag: "input", type: "text", size: "16", autocomplete: "off"}</code></pre>
  1253. */
  1254. defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
  1255. /**
  1256. * @cfg {Boolean} hideTrigger <tt>true</tt> to hide the trigger element and display only the base
  1257. * text field (defaults to <tt>false</tt>)
  1258. */
  1259. hideTrigger:false,
  1260. /**
  1261. * @cfg {Boolean} editable <tt>false</tt> to prevent the user from typing text directly into the field,
  1262. * the field will only respond to a click on the trigger to set the value. (defaults to <tt>true</tt>).
  1263. */
  1264. editable: true,
  1265. /**
  1266. * @cfg {Boolean} readOnly <tt>true</tt> to prevent the user from changing the field, and
  1267. * hides the trigger. Superceeds the editable and hideTrigger options if the value is true.
  1268. * (defaults to <tt>false</tt>)
  1269. */
  1270. readOnly: false,
  1271. /**
  1272. * @cfg {String} wrapFocusClass The class added to the to the wrap of the trigger element. Defaults to
  1273. * <tt>x-trigger-wrap-focus</tt>.
  1274. */
  1275. wrapFocusClass: 'x-trigger-wrap-focus',
  1276. /**
  1277. * @hide
  1278. * @method autoSize
  1279. */
  1280. autoSize: Ext.emptyFn,
  1281. // private
  1282. monitorTab : true,
  1283. // private
  1284. deferHeight : true,
  1285. // private
  1286. mimicing : false,
  1287. actionMode: 'wrap',
  1288. defaultTriggerWidth: 17,
  1289. // private
  1290. onResize : function(w, h){
  1291. Ext.form.TriggerField.superclass.onResize.call(this, w, h);
  1292. var tw = this.getTriggerWidth();
  1293. if(Ext.isNumber(w)){
  1294. this.el.setWidth(w - tw);
  1295. }
  1296. this.wrap.setWidth(this.el.getWidth() + tw);
  1297. },
  1298. getTriggerWidth: function(){
  1299. var tw = this.trigger.getWidth();
  1300. if(!this.hideTrigger && !this.readOnly && tw === 0){
  1301. tw = this.defaultTriggerWidth;
  1302. }
  1303. return tw;
  1304. },
  1305. // private
  1306. alignErrorIcon : function(){
  1307. if(this.wrap){
  1308. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  1309. }
  1310. },
  1311. // private
  1312. onRender : function(ct, position){
  1313. this.doc = Ext.isIE ? Ext.getBody() : Ext.getDoc();
  1314. Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
  1315. this.wrap = this.el.wrap({cls: 'x-form-field-wrap x-form-field-trigger-wrap'});
  1316. this.trigger = this.wrap.createChild(this.triggerConfig ||
  1317. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.triggerClass});
  1318. this.initTrigger();
  1319. if(!this.width){
  1320. this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
  1321. }
  1322. this.resizeEl = this.positionEl = this.wrap;
  1323. },
  1324. getWidth: function() {
  1325. return(this.el.getWidth() + this.trigger.getWidth());
  1326. },
  1327. updateEditState: function(){
  1328. if(this.rendered){
  1329. if (this.readOnly) {
  1330. this.el.dom.readOnly = true;
  1331. this.el.addClass('x-trigger-noedit');
  1332. this.mun(this.el, 'click', this.onTriggerClick, this);
  1333. this.trigger.setDisplayed(false);
  1334. } else {
  1335. if (!this.editable) {
  1336. this.el.dom.readOnly = true;
  1337. this.el.addClass('x-trigger-noedit');
  1338. this.mon(this.el, 'click', this.onTriggerClick, this);
  1339. } else {
  1340. this.el.dom.readOnly = false;
  1341. this.el.removeClass('x-trigger-noedit');
  1342. this.mun(this.el, 'click', this.onTriggerClick, this);
  1343. }
  1344. this.trigger.setDisplayed(!this.hideTrigger);
  1345. }
  1346. this.onResize(this.width || this.wrap.getWidth());
  1347. }
  1348. },
  1349. /**
  1350. * Changes the hidden status of the trigger.
  1351. * @param {Boolean} hideTrigger True to hide the trigger, false to show it.
  1352. */
  1353. setHideTrigger: function(hideTrigger){
  1354. if(hideTrigger != this.hideTrigger){
  1355. this.hideTrigger = hideTrigger;
  1356. this.updateEditState();
  1357. }
  1358. },
  1359. /**
  1360. * Allow or prevent the user from directly editing the field text. If false is passed,
  1361. * the user will only be able to modify the field using the trigger. Will also add
  1362. * a click event to the text field which will call the trigger. This method
  1363. * is the runtime equivalent of setting the {@link #editable} config option at config time.
  1364. * @param {Boolean} value True to allow the user to directly edit the field text.
  1365. */
  1366. setEditable: function(editable){
  1367. if(editable != this.editable){
  1368. this.editable = editable;
  1369. this.updateEditState();
  1370. }
  1371. },
  1372. /**
  1373. * Setting this to true will supersede settings {@link #editable} and {@link #hideTrigger}.
  1374. * Setting this to false will defer back to {@link #editable} and {@link #hideTrigger}. This method
  1375. * is the runtime equivalent of setting the {@link #readOnly} config option at config time.
  1376. * @param {Boolean} value True to prevent the user changing the field and explicitly
  1377. * hide the trigger.
  1378. */
  1379. setReadOnly: function(readOnly){
  1380. if(readOnly != this.readOnly){
  1381. this.readOnly = readOnly;
  1382. this.updateEditState();
  1383. }
  1384. },
  1385. afterRender : function(){
  1386. Ext.form.TriggerField.superclass.afterRender.call(this);
  1387. this.updateEditState();
  1388. },
  1389. // private
  1390. initTrigger : function(){
  1391. this.mon(this.trigger, 'click', this.onTriggerClick, this, {preventDefault:true});
  1392. this.trigger.addClassOnOver('x-form-trigger-over');
  1393. this.trigger.addClassOnClick('x-form-trigger-click');
  1394. },
  1395. // private
  1396. onDestroy : function(){
  1397. Ext.destroy(this.trigger, this.wrap);
  1398. if (this.mimicing){
  1399. this.doc.un('mousedown', this.mimicBlur, this);
  1400. }
  1401. delete this.doc;
  1402. Ext.form.TriggerField.superclass.onDestroy.call(this);
  1403. },
  1404. // private
  1405. onFocus : function(){
  1406. Ext.form.TriggerField.superclass.onFocus.call(this);
  1407. if(!this.mimicing){
  1408. this.wrap.addClass(this.wrapFocusClass);
  1409. this.mimicing = true;
  1410. this.doc.on('mousedown', this.mimicBlur, this, {delay: 10});
  1411. if(this.monitorTab){
  1412. this.on('specialkey', this.checkTab, this);
  1413. }
  1414. }
  1415. },
  1416. // private
  1417. checkTab : function(me, e){
  1418. if(e.getKey() == e.TAB){
  1419. this.triggerBlur();
  1420. }
  1421. },
  1422. // private
  1423. onBlur : Ext.emptyFn,
  1424. // private
  1425. mimicBlur : function(e){
  1426. if(!this.isDestroyed && !this.wrap.contains(e.target) && this.validateBlur(e)){
  1427. this.triggerBlur();
  1428. }
  1429. },
  1430. // private
  1431. triggerBlur : function(){
  1432. this.mimicing = false;
  1433. this.doc.un('mousedown', this.mimicBlur, this);
  1434. if(this.monitorTab && this.el){
  1435. this.un('specialkey', this.checkTab, this);
  1436. }
  1437. Ext.form.TriggerField.superclass.onBlur.call(this);
  1438. if(this.wrap){
  1439. this.wrap.removeClass(this.wrapFocusClass);
  1440. }
  1441. },
  1442. beforeBlur : Ext.emptyFn,
  1443. // private
  1444. // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
  1445. validateBlur : function(e){
  1446. return true;
  1447. },
  1448. /**
  1449. * The function that should handle the trigger's click event. This method does nothing by default
  1450. * until overridden by an implementing function. See Ext.form.ComboBox and Ext.form.DateField for
  1451. * sample implementations.
  1452. * @method
  1453. * @param {EventObject} e
  1454. */
  1455. onTriggerClick : Ext.emptyFn
  1456. /**
  1457. * @cfg {Boolean} grow @hide
  1458. */
  1459. /**
  1460. * @cfg {Number} growMin @hide
  1461. */
  1462. /**
  1463. * @cfg {Number} growMax @hide
  1464. */
  1465. });
  1466. /**
  1467. * @class Ext.form.TwinTriggerField
  1468. * @extends Ext.form.TriggerField
  1469. * TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
  1470. * to be extended by an implementing class. For an example of implementing this class, see the custom
  1471. * SearchField implementation here:
  1472. * <a href="http://extjs.com/deploy/ext/examples/form/custom.html">http://extjs.com/deploy/ext/examples/form/custom.html</a>
  1473. */
  1474. Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, {
  1475. /**
  1476. * @cfg {Mixed} triggerConfig
  1477. * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the trigger elements
  1478. * for this Field. (Optional).</p>
  1479. * <p>Specify this when you need a customized element to contain the two trigger elements for this Field.
  1480. * Each trigger element must be marked by the CSS class <tt>x-form-trigger</tt> (also see
  1481. * <tt>{@link #trigger1Class}</tt> and <tt>{@link #trigger2Class}</tt>).</p>
  1482. * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing,
  1483. * positioning and appearance of the triggers.</p>
  1484. */
  1485. /**
  1486. * @cfg {String} trigger1Class
  1487. * An additional CSS class used to style the trigger button. The trigger will always get the
  1488. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  1489. */
  1490. /**
  1491. * @cfg {String} trigger2Class
  1492. * An additional CSS class used to style the trigger button. The trigger will always get the
  1493. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  1494. */
  1495. initComponent : function(){
  1496. Ext.form.TwinTriggerField.superclass.initComponent.call(this);
  1497. this.triggerConfig = {
  1498. tag:'span', cls:'x-form-twin-triggers', cn:[
  1499. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.trigger1Class},
  1500. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.trigger2Class}
  1501. ]};
  1502. },
  1503. getTrigger : function(index){
  1504. return this.triggers[index];
  1505. },
  1506. afterRender: function(){
  1507. Ext.form.TwinTriggerField.superclass.afterRender.call(this);
  1508. var triggers = this.triggers,
  1509. i = 0,
  1510. len = triggers.length;
  1511. for(; i < len; ++i){
  1512. if(this['hideTrigger' + (i + 1)]){
  1513. triggers[i].hide();
  1514. }
  1515. }
  1516. },
  1517. initTrigger : function(){
  1518. var ts = this.trigger.select('.x-form-trigger', true),
  1519. triggerField = this;
  1520. ts.each(function(t, all, index){
  1521. var triggerIndex = 'Trigger'+(index+1);
  1522. t.hide = function(){
  1523. var w = triggerField.wrap.getWidth();
  1524. this.dom.style.display = 'none';
  1525. triggerField.el.setWidth(w-triggerField.trigger.getWidth());
  1526. triggerField['hidden' + triggerIndex] = true;
  1527. };
  1528. t.show = function(){
  1529. var w = triggerField.wrap.getWidth();
  1530. this.dom.style.display = '';
  1531. triggerField.el.setWidth(w-triggerField.trigger.getWidth());
  1532. triggerField['hidden' + triggerIndex] = false;
  1533. };
  1534. this.mon(t, 'click', this['on'+triggerIndex+'Click'], this, {preventDefault:true});
  1535. t.addClassOnOver('x-form-trigger-over');
  1536. t.addClassOnClick('x-form-trigger-click');
  1537. }, this);
  1538. this.triggers = ts.elements;
  1539. },
  1540. getTriggerWidth: function(){
  1541. var tw = 0;
  1542. Ext.each(this.triggers, function(t, index){
  1543. var triggerIndex = 'Trigger' + (index + 1),
  1544. w = t.getWidth();
  1545. if(w === 0 && !this['hidden' + triggerIndex]){
  1546. tw += this.defaultTriggerWidth;
  1547. }else{
  1548. tw += w;
  1549. }
  1550. }, this);
  1551. return tw;
  1552. },
  1553. // private
  1554. onDestroy : function() {
  1555. Ext.destroy(this.triggers);
  1556. Ext.form.TwinTriggerField.superclass.onDestroy.call(this);
  1557. },
  1558. /**
  1559. * The function that should handle the trigger's click event. This method does nothing by default
  1560. * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
  1561. * for additional information.
  1562. * @method
  1563. * @param {EventObject} e
  1564. */
  1565. onTrigger1Click : Ext.emptyFn,
  1566. /**
  1567. * The function that should handle the trigger's click event. This method does nothing by default
  1568. * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
  1569. * for additional information.
  1570. * @method
  1571. * @param {EventObject} e
  1572. */
  1573. onTrigger2Click : Ext.emptyFn
  1574. });
  1575. Ext.reg('trigger', Ext.form.TriggerField);
  1576. Ext.reg('twintrigger', Ext.form.TwinTriggerField);/**
  1577. * @class Ext.form.TextArea
  1578. * @extends Ext.form.TextField
  1579. * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
  1580. * support for auto-sizing.
  1581. * @constructor
  1582. * Creates a new TextArea
  1583. * @param {Object} config Configuration options
  1584. * @xtype textarea
  1585. */
  1586. Ext.form.TextArea = Ext.extend(Ext.form.TextField, {
  1587. /**
  1588. * @cfg {Number} growMin The minimum height to allow when <tt>{@link Ext.form.TextField#grow grow}=true</tt>
  1589. * (defaults to <tt>60</tt>)
  1590. */
  1591. growMin : 60,
  1592. /**
  1593. * @cfg {Number} growMax The maximum height to allow when <tt>{@link Ext.form.TextField#grow grow}=true</tt>
  1594. * (defaults to <tt>1000</tt>)
  1595. */
  1596. growMax: 1000,
  1597. growAppend : '&#160;\n&#160;',
  1598. enterIsSpecial : false,
  1599. /**
  1600. * @cfg {Boolean} preventScrollbars <tt>true</tt> to prevent scrollbars from appearing regardless of how much text is
  1601. * in the field. This option is only relevant when {@link #grow} is <tt>true</tt>. Equivalent to setting overflow: hidden, defaults to
  1602. * <tt>false</tt>.
  1603. */
  1604. preventScrollbars: false,
  1605. /**
  1606. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
  1607. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  1608. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  1609. * <pre><code>{tag: "textarea", style: "width:100px;height:60px;", autocomplete: "off"}</code></pre>
  1610. */
  1611. // private
  1612. onRender : function(ct, position){
  1613. if(!this.el){
  1614. this.defaultAutoCreate = {
  1615. tag: "textarea",
  1616. style:"width:100px;height:60px;",
  1617. autocomplete: "off"
  1618. };
  1619. }
  1620. Ext.form.TextArea.superclass.onRender.call(this, ct, position);
  1621. if(this.grow){
  1622. this.textSizeEl = Ext.DomHelper.append(document.body, {
  1623. tag: "pre", cls: "x-form-grow-sizer"
  1624. });
  1625. if(this.preventScrollbars){
  1626. this.el.setStyle("overflow", "hidden");
  1627. }
  1628. this.el.setHeight(this.growMin);
  1629. }
  1630. },
  1631. onDestroy : function(){
  1632. Ext.removeNode(this.textSizeEl);
  1633. Ext.form.TextArea.superclass.onDestroy.call(this);
  1634. },
  1635. fireKey : function(e){
  1636. if(e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() != e.ENTER || e.hasModifier()))){
  1637. this.fireEvent("specialkey", this, e);
  1638. }
  1639. },
  1640. // private
  1641. doAutoSize : function(e){
  1642. return !e.isNavKeyPress() || e.getKey() == e.ENTER;
  1643. },
  1644. // inherit docs
  1645. filterValidation: function(e) {
  1646. if(!e.isNavKeyPress() || (!this.enterIsSpecial && e.keyCode == e.ENTER)){
  1647. this.validationTask.delay(this.validationDelay);
  1648. }
  1649. },
  1650. /**
  1651. * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
  1652. * This only takes effect if grow = true, and fires the {@link #autosize} event if the height changes.
  1653. */
  1654. autoSize: function(){
  1655. if(!this.grow || !this.textSizeEl){
  1656. return;
  1657. }
  1658. var el = this.el,
  1659. v = Ext.util.Format.htmlEncode(el.dom.value),
  1660. ts = this.textSizeEl,
  1661. h;
  1662. Ext.fly(ts).setWidth(this.el.getWidth());
  1663. if(v.length < 1){
  1664. v = "&#160;&#160;";
  1665. }else{
  1666. v += this.growAppend;
  1667. if(Ext.isIE){
  1668. v = v.replace(/\n/g, '&#160;<br />');
  1669. }
  1670. }
  1671. ts.innerHTML = v;
  1672. h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
  1673. if(h != this.lastHeight){
  1674. this.lastHeight = h;
  1675. this.el.setHeight(h);
  1676. this.fireEvent("autosize", this, h);
  1677. }
  1678. }
  1679. });
  1680. Ext.reg('textarea', Ext.form.TextArea);/**
  1681. * @class Ext.form.NumberField
  1682. * @extends Ext.form.TextField
  1683. * Numeric text field that provides automatic keystroke filtering and numeric validation.
  1684. * @constructor
  1685. * Creates a new NumberField
  1686. * @param {Object} config Configuration options
  1687. * @xtype numberfield
  1688. */
  1689. Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
  1690. /**
  1691. * @cfg {RegExp} stripCharsRe @hide
  1692. */
  1693. /**
  1694. * @cfg {RegExp} maskRe @hide
  1695. */
  1696. /**
  1697. * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
  1698. */
  1699. fieldClass: "x-form-field x-form-num-field",
  1700. /**
  1701. * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
  1702. */
  1703. allowDecimals : true,
  1704. /**
  1705. * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
  1706. */
  1707. decimalSeparator : ".",
  1708. /**
  1709. * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
  1710. */
  1711. decimalPrecision : 2,
  1712. /**
  1713. * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
  1714. */
  1715. allowNegative : true,
  1716. /**
  1717. * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
  1718. */
  1719. minValue : Number.NEGATIVE_INFINITY,
  1720. /**
  1721. * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
  1722. */
  1723. maxValue : Number.MAX_VALUE,
  1724. /**
  1725. * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
  1726. */
  1727. minText : "The minimum value for this field is {0}",
  1728. /**
  1729. * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
  1730. */
  1731. maxText : "The maximum value for this field is {0}",
  1732. /**
  1733. * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
  1734. * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
  1735. */
  1736. nanText : "{0} is not a valid number",
  1737. /**
  1738. * @cfg {String} baseChars The base set of characters to evaluate as valid numbers (defaults to '0123456789').
  1739. */
  1740. baseChars : "0123456789",
  1741. /**
  1742. * @cfg {Boolean} autoStripChars True to automatically strip not allowed characters from the field. Defaults to <tt>false</tt>
  1743. */
  1744. autoStripChars: false,
  1745. // private
  1746. initEvents : function() {
  1747. var allowed = this.baseChars + '';
  1748. if (this.allowDecimals) {
  1749. allowed += this.decimalSeparator;
  1750. }
  1751. if (this.allowNegative) {
  1752. allowed += '-';
  1753. }
  1754. allowed = Ext.escapeRe(allowed);
  1755. this.maskRe = new RegExp('[' + allowed + ']');
  1756. if (this.autoStripChars) {
  1757. this.stripCharsRe = new RegExp('[^' + allowed + ']', 'gi');
  1758. }
  1759. Ext.form.NumberField.superclass.initEvents.call(this);
  1760. },
  1761. /**
  1762. * Runs all of NumberFields validations and returns an array of any errors. Note that this first
  1763. * runs TextField's validations, so the returned array is an amalgamation of all field errors.
  1764. * The additional validations run test that the value is a number, and that it is within the
  1765. * configured min and max values.
  1766. * @param {Mixed} value The value to get errors for (defaults to the current field value)
  1767. * @return {Array} All validation errors for this field
  1768. */
  1769. getErrors: function(value) {
  1770. var errors = Ext.form.NumberField.superclass.getErrors.apply(this, arguments);
  1771. value = Ext.isDefined(value) ? value : this.processValue(this.getRawValue());
  1772. if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
  1773. return errors;
  1774. }
  1775. value = String(value).replace(this.decimalSeparator, ".");
  1776. if(isNaN(value)){
  1777. errors.push(String.format(this.nanText, value));
  1778. }
  1779. var num = this.parseValue(value);
  1780. if (num < this.minValue) {
  1781. errors.push(String.format(this.minText, this.minValue));
  1782. }
  1783. if (num > this.maxValue) {
  1784. errors.push(String.format(this.maxText, this.maxValue));
  1785. }
  1786. return errors;
  1787. },
  1788. getValue : function() {
  1789. return this.fixPrecision(this.parseValue(Ext.form.NumberField.superclass.getValue.call(this)));
  1790. },
  1791. setValue : function(v) {
  1792. v = Ext.isNumber(v) ? v : parseFloat(String(v).replace(this.decimalSeparator, "."));
  1793. v = this.fixPrecision(v);
  1794. v = isNaN(v) ? '' : String(v).replace(".", this.decimalSeparator);
  1795. return Ext.form.NumberField.superclass.setValue.call(this, v);
  1796. },
  1797. /**
  1798. * Replaces any existing {@link #minValue} with the new value.
  1799. * @param {Number} value The minimum value
  1800. */
  1801. setMinValue : function(value) {
  1802. this.minValue = Ext.num(value, Number.NEGATIVE_INFINITY);
  1803. },
  1804. /**
  1805. * Replaces any existing {@link #maxValue} with the new value.
  1806. * @param {Number} value The maximum value
  1807. */
  1808. setMaxValue : function(value) {
  1809. this.maxValue = Ext.num(value, Number.MAX_VALUE);
  1810. },
  1811. // private
  1812. parseValue : function(value) {
  1813. value = parseFloat(String(value).replace(this.decimalSeparator, "."));
  1814. return isNaN(value) ? '' : value;
  1815. },
  1816. /**
  1817. * @private
  1818. *
  1819. */
  1820. fixPrecision : function(value) {
  1821. var nan = isNaN(value);
  1822. if (!this.allowDecimals || this.decimalPrecision == -1 || nan || !value) {
  1823. return nan ? '' : value;
  1824. }
  1825. return parseFloat(parseFloat(value).toFixed(this.decimalPrecision));
  1826. },
  1827. beforeBlur : function() {
  1828. var v = this.parseValue(this.getRawValue());
  1829. if (!Ext.isEmpty(v)) {
  1830. this.setValue(v);
  1831. }
  1832. }
  1833. });
  1834. Ext.reg('numberfield', Ext.form.NumberField);
  1835. /**
  1836. * @class Ext.form.DateField
  1837. * @extends Ext.form.TriggerField
  1838. * Provides a date input field with a {@link Ext.DatePicker} dropdown and automatic date validation.
  1839. * @constructor
  1840. * Create a new DateField
  1841. * @param {Object} config
  1842. * @xtype datefield
  1843. */
  1844. Ext.form.DateField = Ext.extend(Ext.form.TriggerField, {
  1845. /**
  1846. * @cfg {String} format
  1847. * The default date format string which can be overriden for localization support. The format must be
  1848. * valid according to {@link Date#parseDate} (defaults to <tt>'m/d/Y'</tt>).
  1849. */
  1850. format : "m/d/Y",
  1851. /**
  1852. * @cfg {String} altFormats
  1853. * Multiple date formats separated by "<tt>|</tt>" to try when parsing a user input value and it
  1854. * does not match the defined format (defaults to
  1855. * <tt>'m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j'</tt>).
  1856. */
  1857. altFormats : "m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j",
  1858. /**
  1859. * @cfg {String} disabledDaysText
  1860. * The tooltip to display when the date falls on a disabled day (defaults to <tt>'Disabled'</tt>)
  1861. */
  1862. disabledDaysText : "Disabled",
  1863. /**
  1864. * @cfg {String} disabledDatesText
  1865. * The tooltip text to display when the date falls on a disabled date (defaults to <tt>'Disabled'</tt>)
  1866. */
  1867. disabledDatesText : "Disabled",
  1868. /**
  1869. * @cfg {String} minText
  1870. * The error text to display when the date in the cell is before <tt>{@link #minValue}</tt> (defaults to
  1871. * <tt>'The date in this field must be after {minValue}'</tt>).
  1872. */
  1873. minText : "The date in this field must be equal to or after {0}",
  1874. /**
  1875. * @cfg {String} maxText
  1876. * The error text to display when the date in the cell is after <tt>{@link #maxValue}</tt> (defaults to
  1877. * <tt>'The date in this field must be before {maxValue}'</tt>).
  1878. */
  1879. maxText : "The date in this field must be equal to or before {0}",
  1880. /**
  1881. * @cfg {String} invalidText
  1882. * The error text to display when the date in the field is invalid (defaults to
  1883. * <tt>'{value} is not a valid date - it must be in the format {format}'</tt>).
  1884. */
  1885. invalidText : "{0} is not a valid date - it must be in the format {1}",
  1886. /**
  1887. * @cfg {String} triggerClass
  1888. * An additional CSS class used to style the trigger button. The trigger will always get the
  1889. * class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
  1890. * (defaults to <tt>'x-form-date-trigger'</tt> which displays a calendar icon).
  1891. */
  1892. triggerClass : 'x-form-date-trigger',
  1893. /**
  1894. * @cfg {Boolean} showToday
  1895. * <tt>false</tt> to hide the footer area of the DatePicker containing the Today button and disable
  1896. * the keyboard handler for spacebar that selects the current date (defaults to <tt>true</tt>).
  1897. */
  1898. showToday : true,
  1899. /**
  1900. * @cfg {Number} startDay
  1901. * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
  1902. */
  1903. startDay : 0,
  1904. /**
  1905. * @cfg {Date/String} minValue
  1906. * The minimum allowed date. Can be either a Javascript date object or a string date in a
  1907. * valid format (defaults to null).
  1908. */
  1909. /**
  1910. * @cfg {Date/String} maxValue
  1911. * The maximum allowed date. Can be either a Javascript date object or a string date in a
  1912. * valid format (defaults to null).
  1913. */
  1914. /**
  1915. * @cfg {Array} disabledDays
  1916. * An array of days to disable, 0 based (defaults to null). Some examples:<pre><code>
  1917. // disable Sunday and Saturday:
  1918. disabledDays: [0, 6]
  1919. // disable weekdays:
  1920. disabledDays: [1,2,3,4,5]
  1921. * </code></pre>
  1922. */
  1923. /**
  1924. * @cfg {Array} disabledDates
  1925. * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
  1926. * expression so they are very powerful. Some examples:<pre><code>
  1927. // disable these exact dates:
  1928. disabledDates: ["03/08/2003", "09/16/2003"]
  1929. // disable these days for every year:
  1930. disabledDates: ["03/08", "09/16"]
  1931. // only match the beginning (useful if you are using short years):
  1932. disabledDates: ["^03/08"]
  1933. // disable every day in March 2006:
  1934. disabledDates: ["03/../2006"]
  1935. // disable every day in every March:
  1936. disabledDates: ["^03"]
  1937. * </code></pre>
  1938. * Note that the format of the dates included in the array should exactly match the {@link #format} config.
  1939. * In order to support regular expressions, if you are using a {@link #format date format} that has "." in
  1940. * it, you will have to escape the dot when restricting dates. For example: <tt>["03\\.08\\.03"]</tt>.
  1941. */
  1942. /**
  1943. * @cfg {String/Object} autoCreate
  1944. * A {@link Ext.DomHelper DomHelper element specification object}, or <tt>true</tt> for the default element
  1945. * specification object:<pre><code>
  1946. * autoCreate: {tag: "input", type: "text", size: "10", autocomplete: "off"}
  1947. * </code></pre>
  1948. */
  1949. // private
  1950. defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
  1951. // in the absence of a time value, a default value of 12 noon will be used
  1952. // (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
  1953. initTime: '12', // 24 hour format
  1954. initTimeFormat: 'H',
  1955. // PUBLIC -- to be documented
  1956. safeParse : function(value, format) {
  1957. if (Date.formatContainsHourInfo(format)) {
  1958. // if parse format contains hour information, no DST adjustment is necessary
  1959. return Date.parseDate(value, format);
  1960. } else {
  1961. // set time to 12 noon, then clear the time
  1962. var parsedDate = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat);
  1963. if (parsedDate) {
  1964. return parsedDate.clearTime();
  1965. }
  1966. }
  1967. },
  1968. initComponent : function(){
  1969. Ext.form.DateField.superclass.initComponent.call(this);
  1970. this.addEvents(
  1971. /**
  1972. * @event select
  1973. * Fires when a date is selected via the date picker.
  1974. * @param {Ext.form.DateField} this
  1975. * @param {Date} date The date that was selected
  1976. */
  1977. 'select'
  1978. );
  1979. if(Ext.isString(this.minValue)){
  1980. this.minValue = this.parseDate(this.minValue);
  1981. }
  1982. if(Ext.isString(this.maxValue)){
  1983. this.maxValue = this.parseDate(this.maxValue);
  1984. }
  1985. this.disabledDatesRE = null;
  1986. this.initDisabledDays();
  1987. },
  1988. initEvents: function() {
  1989. Ext.form.DateField.superclass.initEvents.call(this);
  1990. this.keyNav = new Ext.KeyNav(this.el, {
  1991. "down": function(e) {
  1992. this.onTriggerClick();
  1993. },
  1994. scope: this,
  1995. forceKeyDown: true
  1996. });
  1997. },
  1998. // private
  1999. initDisabledDays : function(){
  2000. if(this.disabledDates){
  2001. var dd = this.disabledDates,
  2002. len = dd.length - 1,
  2003. re = "(?:";
  2004. Ext.each(dd, function(d, i){
  2005. re += Ext.isDate(d) ? '^' + Ext.escapeRe(d.dateFormat(this.format)) + '$' : dd[i];
  2006. if(i != len){
  2007. re += '|';
  2008. }
  2009. }, this);
  2010. this.disabledDatesRE = new RegExp(re + ')');
  2011. }
  2012. },
  2013. /**
  2014. * Replaces any existing disabled dates with new values and refreshes the DatePicker.
  2015. * @param {Array} disabledDates An array of date strings (see the <tt>{@link #disabledDates}</tt> config
  2016. * for details on supported values) used to disable a pattern of dates.
  2017. */
  2018. setDisabledDates : function(dd){
  2019. this.disabledDates = dd;
  2020. this.initDisabledDays();
  2021. if(this.menu){
  2022. this.menu.picker.setDisabledDates(this.disabledDatesRE);
  2023. }
  2024. },
  2025. /**
  2026. * Replaces any existing disabled days (by index, 0-6) with new values and refreshes the DatePicker.
  2027. * @param {Array} disabledDays An array of disabled day indexes. See the <tt>{@link #disabledDays}</tt>
  2028. * config for details on supported values.
  2029. */
  2030. setDisabledDays : function(dd){
  2031. this.disabledDays = dd;
  2032. if(this.menu){
  2033. this.menu.picker.setDisabledDays(dd);
  2034. }
  2035. },
  2036. /**
  2037. * Replaces any existing <tt>{@link #minValue}</tt> with the new value and refreshes the DatePicker.
  2038. * @param {Date} value The minimum date that can be selected
  2039. */
  2040. setMinValue : function(dt){
  2041. this.minValue = (Ext.isString(dt) ? this.parseDate(dt) : dt);
  2042. if(this.menu){
  2043. this.menu.picker.setMinDate(this.minValue);
  2044. }
  2045. },
  2046. /**
  2047. * Replaces any existing <tt>{@link #maxValue}</tt> with the new value and refreshes the DatePicker.
  2048. * @param {Date} value The maximum date that can be selected
  2049. */
  2050. setMaxValue : function(dt){
  2051. this.maxValue = (Ext.isString(dt) ? this.parseDate(dt) : dt);
  2052. if(this.menu){
  2053. this.menu.picker.setMaxDate(this.maxValue);
  2054. }
  2055. },
  2056. /**
  2057. * Runs all of NumberFields validations and returns an array of any errors. Note that this first
  2058. * runs TextField's validations, so the returned array is an amalgamation of all field errors.
  2059. * The additional validation checks are testing that the date format is valid, that the chosen
  2060. * date is within the min and max date constraints set, that the date chosen is not in the disabledDates
  2061. * regex and that the day chosed is not one of the disabledDays.
  2062. * @param {Mixed} value The value to get errors for (defaults to the current field value)
  2063. * @return {Array} All validation errors for this field
  2064. */
  2065. getErrors: function(value) {
  2066. var errors = Ext.form.DateField.superclass.getErrors.apply(this, arguments);
  2067. value = this.formatDate(value || this.processValue(this.getRawValue()));
  2068. if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
  2069. return errors;
  2070. }
  2071. var svalue = value;
  2072. value = this.parseDate(value);
  2073. if (!value) {
  2074. errors.push(String.format(this.invalidText, svalue, this.format));
  2075. return errors;
  2076. }
  2077. var time = value.getTime();
  2078. if (this.minValue && time < this.minValue.clearTime().getTime()) {
  2079. errors.push(String.format(this.minText, this.formatDate(this.minValue)));
  2080. }
  2081. if (this.maxValue && time > this.maxValue.clearTime().getTime()) {
  2082. errors.push(String.format(this.maxText, this.formatDate(this.maxValue)));
  2083. }
  2084. if (this.disabledDays) {
  2085. var day = value.getDay();
  2086. for(var i = 0; i < this.disabledDays.length; i++) {
  2087. if (day === this.disabledDays[i]) {
  2088. errors.push(this.disabledDaysText);
  2089. break;
  2090. }
  2091. }
  2092. }
  2093. var fvalue = this.formatDate(value);
  2094. if (this.disabledDatesRE && this.disabledDatesRE.test(fvalue)) {
  2095. errors.push(String.format(this.disabledDatesText, fvalue));
  2096. }
  2097. return errors;
  2098. },
  2099. // private
  2100. // Provides logic to override the default TriggerField.validateBlur which just returns true
  2101. validateBlur : function(){
  2102. return !this.menu || !this.menu.isVisible();
  2103. },
  2104. /**
  2105. * Returns the current date value of the date field.
  2106. * @return {Date} The date value
  2107. */
  2108. getValue : function(){
  2109. return this.parseDate(Ext.form.DateField.superclass.getValue.call(this)) || "";
  2110. },
  2111. /**
  2112. * Sets the value of the date field. You can pass a date object or any string that can be
  2113. * parsed into a valid date, using <tt>{@link #format}</tt> as the date format, according
  2114. * to the same rules as {@link Date#parseDate} (the default format used is <tt>"m/d/Y"</tt>).
  2115. * <br />Usage:
  2116. * <pre><code>
  2117. //All of these calls set the same date value (May 4, 2006)
  2118. //Pass a date object:
  2119. var dt = new Date('5/4/2006');
  2120. dateField.setValue(dt);
  2121. //Pass a date string (default format):
  2122. dateField.setValue('05/04/2006');
  2123. //Pass a date string (custom format):
  2124. dateField.format = 'Y-m-d';
  2125. dateField.setValue('2006-05-04');
  2126. </code></pre>
  2127. * @param {String/Date} date The date or valid date string
  2128. * @return {Ext.form.Field} this
  2129. */
  2130. setValue : function(date){
  2131. return Ext.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
  2132. },
  2133. // private
  2134. parseDate : function(value) {
  2135. if(!value || Ext.isDate(value)){
  2136. return value;
  2137. }
  2138. var v = this.safeParse(value, this.format),
  2139. af = this.altFormats,
  2140. afa = this.altFormatsArray;
  2141. if (!v && af) {
  2142. afa = afa || af.split("|");
  2143. for (var i = 0, len = afa.length; i < len && !v; i++) {
  2144. v = this.safeParse(value, afa[i]);
  2145. }
  2146. }
  2147. return v;
  2148. },
  2149. // private
  2150. onDestroy : function(){
  2151. Ext.destroy(this.menu, this.keyNav);
  2152. Ext.form.DateField.superclass.onDestroy.call(this);
  2153. },
  2154. // private
  2155. formatDate : function(date){
  2156. return Ext.isDate(date) ? date.dateFormat(this.format) : date;
  2157. },
  2158. /**
  2159. * @method onTriggerClick
  2160. * @hide
  2161. */
  2162. // private
  2163. // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
  2164. onTriggerClick : function(){
  2165. if(this.disabled){
  2166. return;
  2167. }
  2168. if(this.menu == null){
  2169. this.menu = new Ext.menu.DateMenu({
  2170. hideOnClick: false,
  2171. focusOnSelect: false
  2172. });
  2173. }
  2174. this.onFocus();
  2175. Ext.apply(this.menu.picker, {
  2176. minDate : this.minValue,
  2177. maxDate : this.maxValue,
  2178. disabledDatesRE : this.disabledDatesRE,
  2179. disabledDatesText : this.disabledDatesText,
  2180. disabledDays : this.disabledDays,
  2181. disabledDaysText : this.disabledDaysText,
  2182. format : this.format,
  2183. showToday : this.showToday,
  2184. startDay: this.startDay,
  2185. minText : String.format(this.minText, this.formatDate(this.minValue)),
  2186. maxText : String.format(this.maxText, this.formatDate(this.maxValue))
  2187. });
  2188. this.menu.picker.setValue(this.getValue() || new Date());
  2189. this.menu.show(this.el, "tl-bl?");
  2190. this.menuEvents('on');
  2191. },
  2192. //private
  2193. menuEvents: function(method){
  2194. this.menu[method]('select', this.onSelect, this);
  2195. this.menu[method]('hide', this.onMenuHide, this);
  2196. this.menu[method]('show', this.onFocus, this);
  2197. },
  2198. onSelect: function(m, d){
  2199. this.setValue(d);
  2200. this.fireEvent('select', this, d);
  2201. this.menu.hide();
  2202. },
  2203. onMenuHide: function(){
  2204. this.focus(false, 60);
  2205. this.menuEvents('un');
  2206. },
  2207. // private
  2208. beforeBlur : function(){
  2209. var v = this.parseDate(this.getRawValue());
  2210. if(v){
  2211. this.setValue(v);
  2212. }
  2213. }
  2214. /**
  2215. * @cfg {Boolean} grow @hide
  2216. */
  2217. /**
  2218. * @cfg {Number} growMin @hide
  2219. */
  2220. /**
  2221. * @cfg {Number} growMax @hide
  2222. */
  2223. /**
  2224. * @hide
  2225. * @method autoSize
  2226. */
  2227. });
  2228. Ext.reg('datefield', Ext.form.DateField);
  2229. /**
  2230. * @class Ext.form.DisplayField
  2231. * @extends Ext.form.Field
  2232. * A display-only text field which is not validated and not submitted.
  2233. * @constructor
  2234. * Creates a new DisplayField.
  2235. * @param {Object} config Configuration options
  2236. * @xtype displayfield
  2237. */
  2238. Ext.form.DisplayField = Ext.extend(Ext.form.Field, {
  2239. validationEvent : false,
  2240. validateOnBlur : false,
  2241. defaultAutoCreate : {tag: "div"},
  2242. /**
  2243. * @cfg {String} fieldClass The default CSS class for the field (defaults to <tt>"x-form-display-field"</tt>)
  2244. */
  2245. fieldClass : "x-form-display-field",
  2246. /**
  2247. * @cfg {Boolean} htmlEncode <tt>false</tt> to skip HTML-encoding the text when rendering it (defaults to
  2248. * <tt>false</tt>). This might be useful if you want to include tags in the field's innerHTML rather than
  2249. * rendering them as string literals per the default logic.
  2250. */
  2251. htmlEncode: false,
  2252. // private
  2253. initEvents : Ext.emptyFn,
  2254. isValid : function(){
  2255. return true;
  2256. },
  2257. validate : function(){
  2258. return true;
  2259. },
  2260. getRawValue : function(){
  2261. var v = this.rendered ? this.el.dom.innerHTML : Ext.value(this.value, '');
  2262. if(v === this.emptyText){
  2263. v = '';
  2264. }
  2265. if(this.htmlEncode){
  2266. v = Ext.util.Format.htmlDecode(v);
  2267. }
  2268. return v;
  2269. },
  2270. getValue : function(){
  2271. return this.getRawValue();
  2272. },
  2273. getName: function() {
  2274. return this.name;
  2275. },
  2276. setRawValue : function(v){
  2277. if(this.htmlEncode){
  2278. v = Ext.util.Format.htmlEncode(v);
  2279. }
  2280. return this.rendered ? (this.el.dom.innerHTML = (Ext.isEmpty(v) ? '' : v)) : (this.value = v);
  2281. },
  2282. setValue : function(v){
  2283. this.setRawValue(v);
  2284. return this;
  2285. }
  2286. /**
  2287. * @cfg {String} inputType
  2288. * @hide
  2289. */
  2290. /**
  2291. * @cfg {Boolean} disabled
  2292. * @hide
  2293. */
  2294. /**
  2295. * @cfg {Boolean} readOnly
  2296. * @hide
  2297. */
  2298. /**
  2299. * @cfg {Boolean} validateOnBlur
  2300. * @hide
  2301. */
  2302. /**
  2303. * @cfg {Number} validationDelay
  2304. * @hide
  2305. */
  2306. /**
  2307. * @cfg {String/Boolean} validationEvent
  2308. * @hide
  2309. */
  2310. });
  2311. Ext.reg('displayfield', Ext.form.DisplayField);
  2312. /**
  2313. * @class Ext.form.ComboBox
  2314. * @extends Ext.form.TriggerField
  2315. * <p>A combobox control with support for autocomplete, remote-loading, paging and many other features.</p>
  2316. * <p>A ComboBox works in a similar manner to a traditional HTML &lt;select> field. The difference is
  2317. * that to submit the {@link #valueField}, you must specify a {@link #hiddenName} to create a hidden input
  2318. * field to hold the value of the valueField. The <i>{@link #displayField}</i> is shown in the text field
  2319. * which is named according to the {@link #name}.</p>
  2320. * <p><b><u>Events</u></b></p>
  2321. * <p>To do something when something in ComboBox is selected, configure the select event:<pre><code>
  2322. var cb = new Ext.form.ComboBox({
  2323. // all of your config options
  2324. listeners:{
  2325. scope: yourScope,
  2326. 'select': yourFunction
  2327. }
  2328. });
  2329. // Alternatively, you can assign events after the object is created:
  2330. var cb = new Ext.form.ComboBox(yourOptions);
  2331. cb.on('select', yourFunction, yourScope);
  2332. * </code></pre></p>
  2333. *
  2334. * <p><b><u>ComboBox in Grid</u></b></p>
  2335. * <p>If using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a {@link Ext.grid.Column#renderer renderer}
  2336. * will be needed to show the displayField when the editor is not active. Set up the renderer manually, or implement
  2337. * a reusable render, for example:<pre><code>
  2338. // create reusable renderer
  2339. Ext.util.Format.comboRenderer = function(combo){
  2340. return function(value){
  2341. var record = combo.findRecord(combo.{@link #valueField}, value);
  2342. return record ? record.get(combo.{@link #displayField}) : combo.{@link #valueNotFoundText};
  2343. }
  2344. }
  2345. // create the combo instance
  2346. var combo = new Ext.form.ComboBox({
  2347. {@link #typeAhead}: true,
  2348. {@link #triggerAction}: 'all',
  2349. {@link #lazyRender}:true,
  2350. {@link #mode}: 'local',
  2351. {@link #store}: new Ext.data.ArrayStore({
  2352. id: 0,
  2353. fields: [
  2354. 'myId',
  2355. 'displayText'
  2356. ],
  2357. data: [[1, 'item1'], [2, 'item2']]
  2358. }),
  2359. {@link #valueField}: 'myId',
  2360. {@link #displayField}: 'displayText'
  2361. });
  2362. // snippet of column model used within grid
  2363. var cm = new Ext.grid.ColumnModel([{
  2364. ...
  2365. },{
  2366. header: "Some Header",
  2367. dataIndex: 'whatever',
  2368. width: 130,
  2369. editor: combo, // specify reference to combo instance
  2370. renderer: Ext.util.Format.comboRenderer(combo) // pass combo instance to reusable renderer
  2371. },
  2372. ...
  2373. ]);
  2374. * </code></pre></p>
  2375. *
  2376. * <p><b><u>Filtering</u></b></p>
  2377. * <p>A ComboBox {@link #doQuery uses filtering itself}, for information about filtering the ComboBox
  2378. * store manually see <tt>{@link #lastQuery}</tt>.</p>
  2379. * @constructor
  2380. * Create a new ComboBox.
  2381. * @param {Object} config Configuration options
  2382. * @xtype combo
  2383. */
  2384. Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {
  2385. /**
  2386. * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.
  2387. * Note that if you specify this and the combo is going to be in an {@link Ext.form.BasicForm} or
  2388. * {@link Ext.form.FormPanel}, you must also set <tt>{@link #lazyRender} = true</tt>.
  2389. */
  2390. /**
  2391. * @cfg {Boolean} lazyRender <tt>true</tt> to prevent the ComboBox from rendering until requested
  2392. * (should always be used when rendering into an {@link Ext.Editor} (e.g. {@link Ext.grid.EditorGridPanel Grids}),
  2393. * defaults to <tt>false</tt>).
  2394. */
  2395. /**
  2396. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or <tt>true</tt> for a default
  2397. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  2398. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  2399. * <pre><code>{tag: "input", type: "text", size: "24", autocomplete: "off"}</code></pre>
  2400. */
  2401. /**
  2402. * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to <tt>undefined</tt>).
  2403. * Acceptable values for this property are:
  2404. * <div class="mdetail-params"><ul>
  2405. * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
  2406. * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally,
  2407. * automatically generating {@link Ext.data.Field#name field names} to work with all data components.
  2408. * <div class="mdetail-params"><ul>
  2409. * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
  2410. * A 1-dimensional array will automatically be expanded (each array item will be used for both the combo
  2411. * {@link #valueField} and {@link #displayField})</div></li>
  2412. * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
  2413. * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
  2414. * {@link #valueField}, while the value at index 1 is assumed to be the combo {@link #displayField}.
  2415. * </div></li></ul></div></li></ul></div>
  2416. * <p>See also <tt>{@link #mode}</tt>.</p>
  2417. */
  2418. /**
  2419. * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
  2420. * the dropdown list (defaults to undefined, with no header element)
  2421. */
  2422. // private
  2423. defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
  2424. /**
  2425. * @cfg {Number} listWidth The width (used as a parameter to {@link Ext.Element#setWidth}) of the dropdown
  2426. * list (defaults to the width of the ComboBox field). See also <tt>{@link #minListWidth}</tt>
  2427. */
  2428. /**
  2429. * @cfg {String} displayField The underlying {@link Ext.data.Field#name data field name} to bind to this
  2430. * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field1'</tt> if
  2431. * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
  2432. * the store configuration}).
  2433. * <p>See also <tt>{@link #valueField}</tt>.</p>
  2434. * <p><b>Note</b>: if using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a
  2435. * {@link Ext.grid.Column#renderer renderer} will be needed to show the displayField when the editor is not
  2436. * active.</p>
  2437. */
  2438. /**
  2439. * @cfg {String} valueField The underlying {@link Ext.data.Field#name data value name} to bind to this
  2440. * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field2'</tt> if
  2441. * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
  2442. * the store configuration}).
  2443. * <p><b>Note</b>: use of a <tt>valueField</tt> requires the user to make a selection in order for a value to be
  2444. * mapped. See also <tt>{@link #hiddenName}</tt>, <tt>{@link #hiddenValue}</tt>, and <tt>{@link #displayField}</tt>.</p>
  2445. */
  2446. /**
  2447. * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
  2448. * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically
  2449. * post during a form submission. See also {@link #valueField}.
  2450. */
  2451. /**
  2452. * @cfg {String} hiddenId If <tt>{@link #hiddenName}</tt> is specified, <tt>hiddenId</tt> can also be provided
  2453. * to give the hidden field a unique id. The <tt>hiddenId</tt> and combo {@link Ext.Component#id id} should be
  2454. * different, since no two DOM nodes should share the same id.
  2455. */
  2456. /**
  2457. * @cfg {String} hiddenValue Sets the initial value of the hidden field if {@link #hiddenName} is
  2458. * specified to contain the selected {@link #valueField}, from the Store. Defaults to the configured
  2459. * <tt>{@link Ext.form.Field#value value}</tt>.
  2460. */
  2461. /**
  2462. * @cfg {String} listClass The CSS class to add to the predefined <tt>'x-combo-list'</tt> class
  2463. * applied the dropdown list element (defaults to '').
  2464. */
  2465. listClass : '',
  2466. /**
  2467. * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list
  2468. * (defaults to <tt>'x-combo-selected'</tt>)
  2469. */
  2470. selectedClass : 'x-combo-selected',
  2471. /**
  2472. * @cfg {String} listEmptyText The empty text to display in the data view if no items are found.
  2473. * (defaults to '')
  2474. */
  2475. listEmptyText: '',
  2476. /**
  2477. * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always
  2478. * get the class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
  2479. * (defaults to <tt>'x-form-arrow-trigger'</tt> which displays a downward arrow icon).
  2480. */
  2481. triggerClass : 'x-form-arrow-trigger',
  2482. /**
  2483. * @cfg {Boolean/String} shadow <tt>true</tt> or <tt>"sides"</tt> for the default effect, <tt>"frame"</tt> for
  2484. * 4-way shadow, and <tt>"drop"</tt> for bottom-right
  2485. */
  2486. shadow : 'sides',
  2487. /**
  2488. * @cfg {String/Array} listAlign A valid anchor position value. See <tt>{@link Ext.Element#alignTo}</tt> for details
  2489. * on supported anchor positions and offsets. To specify x/y offsets as well, this value
  2490. * may be specified as an Array of <tt>{@link Ext.Element#alignTo}</tt> method arguments.</p>
  2491. * <pre><code>[ 'tl-bl?', [6,0] ]</code></pre>(defaults to <tt>'tl-bl?'</tt>)
  2492. */
  2493. listAlign : 'tl-bl?',
  2494. /**
  2495. * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown
  2496. * (defaults to <tt>300</tt>)
  2497. */
  2498. maxHeight : 300,
  2499. /**
  2500. * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its
  2501. * distance to the viewport edges (defaults to <tt>90</tt>)
  2502. */
  2503. minHeight : 90,
  2504. /**
  2505. * @cfg {String} triggerAction The action to execute when the trigger is clicked.
  2506. * <div class="mdetail-params"><ul>
  2507. * <li><b><tt>'query'</tt></b> : <b>Default</b>
  2508. * <p class="sub-desc">{@link #doQuery run the query} using the {@link Ext.form.Field#getRawValue raw value}.</p></li>
  2509. * <li><b><tt>'all'</tt></b> :
  2510. * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>
  2511. * </ul></div>
  2512. * <p>See also <code>{@link #queryParam}</code>.</p>
  2513. */
  2514. triggerAction : 'query',
  2515. /**
  2516. * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and
  2517. * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #mode} = 'remote'</tt> or <tt>0</tt> if
  2518. * <tt>{@link #mode} = 'local'</tt>, does not apply if
  2519. * <tt>{@link Ext.form.TriggerField#editable editable} = false</tt>).
  2520. */
  2521. minChars : 4,
  2522. /**
  2523. * @cfg {Boolean} autoSelect <tt>true</tt> to select the first result gathered by the data store (defaults
  2524. * to <tt>true</tt>). A false value would require a manual selection from the dropdown list to set the components value
  2525. * unless the value of ({@link #typeAheadDelay}) were true.
  2526. */
  2527. autoSelect : true,
  2528. /**
  2529. * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being
  2530. * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults
  2531. * to <tt>false</tt>)
  2532. */
  2533. typeAhead : false,
  2534. /**
  2535. * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and
  2536. * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #mode} = 'remote'</tt>
  2537. * or <tt>10</tt> if <tt>{@link #mode} = 'local'</tt>)
  2538. */
  2539. queryDelay : 500,
  2540. /**
  2541. * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.PagingToolbar} is displayed in the
  2542. * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and
  2543. * {@link Ext.PagingToolbar#pageSize limit} parameters. Only applies when <tt>{@link #mode} = 'remote'</tt>
  2544. * (defaults to <tt>0</tt>).
  2545. */
  2546. pageSize : 0,
  2547. /**
  2548. * @cfg {Boolean} selectOnFocus <tt>true</tt> to select any existing text in the field immediately on focus.
  2549. * Only applies when <tt>{@link Ext.form.TriggerField#editable editable} = true</tt> (defaults to
  2550. * <tt>false</tt>).
  2551. */
  2552. selectOnFocus : false,
  2553. /**
  2554. * @cfg {String} queryParam Name of the query ({@link Ext.data.Store#baseParam baseParam} name for the store)
  2555. * as it will be passed on the querystring (defaults to <tt>'query'</tt>)
  2556. */
  2557. queryParam : 'query',
  2558. /**
  2559. * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
  2560. * when <tt>{@link #mode} = 'remote'</tt> (defaults to <tt>'Loading...'</tt>)
  2561. */
  2562. loadingText : 'Loading...',
  2563. /**
  2564. * @cfg {Boolean} resizable <tt>true</tt> to add a resize handle to the bottom of the dropdown list
  2565. * (creates an {@link Ext.Resizable} with 'se' {@link Ext.Resizable#pinned pinned} handles).
  2566. * Defaults to <tt>false</tt>.
  2567. */
  2568. resizable : false,
  2569. /**
  2570. * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if
  2571. * <tt>{@link #resizable} = true</tt> (defaults to <tt>8</tt>)
  2572. */
  2573. handleHeight : 8,
  2574. /**
  2575. * @cfg {String} allQuery The text query to send to the server to return all records for the list
  2576. * with no filtering (defaults to '')
  2577. */
  2578. allQuery: '',
  2579. /**
  2580. * @cfg {String} mode Acceptable values are:
  2581. * <div class="mdetail-params"><ul>
  2582. * <li><b><tt>'remote'</tt></b> : <b>Default</b>
  2583. * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger
  2584. * is clicked. If you do not want the store to be automatically loaded the first time the trigger is
  2585. * clicked, set to <tt>'local'</tt> and manually load the store. To force a requery of the store
  2586. * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>
  2587. * <li><b><tt>'local'</tt></b> :
  2588. * <p class="sub-desc">ComboBox loads local data</p>
  2589. * <pre><code>
  2590. var combo = new Ext.form.ComboBox({
  2591. renderTo: document.body,
  2592. mode: 'local',
  2593. store: new Ext.data.ArrayStore({
  2594. id: 0,
  2595. fields: [
  2596. 'myId', // numeric value is the key
  2597. 'displayText'
  2598. ],
  2599. data: [[1, 'item1'], [2, 'item2']] // data is local
  2600. }),
  2601. valueField: 'myId',
  2602. displayField: 'displayText',
  2603. triggerAction: 'all'
  2604. });
  2605. * </code></pre></li>
  2606. * </ul></div>
  2607. */
  2608. mode: 'remote',
  2609. /**
  2610. * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to <tt>70</tt>, will
  2611. * be ignored if <tt>{@link #listWidth}</tt> has a higher value)
  2612. */
  2613. minListWidth : 70,
  2614. /**
  2615. * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,
  2616. * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)
  2617. */
  2618. forceSelection : false,
  2619. /**
  2620. * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
  2621. * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)
  2622. */
  2623. typeAheadDelay : 250,
  2624. /**
  2625. * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
  2626. * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this
  2627. * default text is used, it means there is no value set and no validation will occur on this field.
  2628. */
  2629. /**
  2630. * @cfg {Boolean} lazyInit <tt>true</tt> to not initialize the list for this combo until the field is focused
  2631. * (defaults to <tt>true</tt>)
  2632. */
  2633. lazyInit : true,
  2634. /**
  2635. * @cfg {Boolean} clearFilterOnReset <tt>true</tt> to clear any filters on the store (when in local mode) when reset is called
  2636. * (defaults to <tt>true</tt>)
  2637. */
  2638. clearFilterOnReset : true,
  2639. /**
  2640. * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
  2641. * If a hiddenName is specified, setting this to true will cause both the hidden field and the element to be submitted.
  2642. * Defaults to <tt>undefined</tt>.
  2643. */
  2644. submitValue: undefined,
  2645. /**
  2646. * The value of the match string used to filter the store. Delete this property to force a requery.
  2647. * Example use:
  2648. * <pre><code>
  2649. var combo = new Ext.form.ComboBox({
  2650. ...
  2651. mode: 'remote',
  2652. ...
  2653. listeners: {
  2654. // delete the previous query in the beforequery event or set
  2655. // combo.lastQuery = null (this will reload the store the next time it expands)
  2656. beforequery: function(qe){
  2657. delete qe.combo.lastQuery;
  2658. }
  2659. }
  2660. });
  2661. * </code></pre>
  2662. * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used
  2663. * configure the combo with <tt>lastQuery=''</tt>. Example use:
  2664. * <pre><code>
  2665. var combo = new Ext.form.ComboBox({
  2666. ...
  2667. mode: 'local',
  2668. triggerAction: 'all',
  2669. lastQuery: ''
  2670. });
  2671. * </code></pre>
  2672. * @property lastQuery
  2673. * @type String
  2674. */
  2675. // private
  2676. initComponent : function(){
  2677. Ext.form.ComboBox.superclass.initComponent.call(this);
  2678. this.addEvents(
  2679. /**
  2680. * @event expand
  2681. * Fires when the dropdown list is expanded
  2682. * @param {Ext.form.ComboBox} combo This combo box
  2683. */
  2684. 'expand',
  2685. /**
  2686. * @event collapse
  2687. * Fires when the dropdown list is collapsed
  2688. * @param {Ext.form.ComboBox} combo This combo box
  2689. */
  2690. 'collapse',
  2691. /**
  2692. * @event beforeselect
  2693. * Fires before a list item is selected. Return false to cancel the selection.
  2694. * @param {Ext.form.ComboBox} combo This combo box
  2695. * @param {Ext.data.Record} record The data record returned from the underlying store
  2696. * @param {Number} index The index of the selected item in the dropdown list
  2697. */
  2698. 'beforeselect',
  2699. /**
  2700. * @event select
  2701. * Fires when a list item is selected
  2702. * @param {Ext.form.ComboBox} combo This combo box
  2703. * @param {Ext.data.Record} record The data record returned from the underlying store
  2704. * @param {Number} index The index of the selected item in the dropdown list
  2705. */
  2706. 'select',
  2707. /**
  2708. * @event beforequery
  2709. * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
  2710. * cancel property to true.
  2711. * @param {Object} queryEvent An object that has these properties:<ul>
  2712. * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>
  2713. * <li><code>query</code> : String <div class="sub-desc">The query</div></li>
  2714. * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
  2715. * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
  2716. * </ul>
  2717. */
  2718. 'beforequery'
  2719. );
  2720. if(this.transform){
  2721. var s = Ext.getDom(this.transform);
  2722. if(!this.hiddenName){
  2723. this.hiddenName = s.name;
  2724. }
  2725. if(!this.store){
  2726. this.mode = 'local';
  2727. var d = [], opts = s.options;
  2728. for(var i = 0, len = opts.length;i < len; i++){
  2729. var o = opts[i],
  2730. value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttributeNode('value').specified) ? o.value : o.text;
  2731. if(o.selected && Ext.isEmpty(this.value, true)) {
  2732. this.value = value;
  2733. }
  2734. d.push([value, o.text]);
  2735. }
  2736. this.store = new Ext.data.ArrayStore({
  2737. idIndex: 0,
  2738. fields: ['value', 'text'],
  2739. data : d,
  2740. autoDestroy: true
  2741. });
  2742. this.valueField = 'value';
  2743. this.displayField = 'text';
  2744. }
  2745. s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference
  2746. if(!this.lazyRender){
  2747. this.target = true;
  2748. this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
  2749. this.render(this.el.parentNode, s);
  2750. }
  2751. Ext.removeNode(s);
  2752. }
  2753. //auto-configure store from local array data
  2754. else if(this.store){
  2755. this.store = Ext.StoreMgr.lookup(this.store);
  2756. if(this.store.autoCreated){
  2757. this.displayField = this.valueField = 'field1';
  2758. if(!this.store.expandData){
  2759. this.displayField = 'field2';
  2760. }
  2761. this.mode = 'local';
  2762. }
  2763. }
  2764. this.selectedIndex = -1;
  2765. if(this.mode == 'local'){
  2766. if(!Ext.isDefined(this.initialConfig.queryDelay)){
  2767. this.queryDelay = 10;
  2768. }
  2769. if(!Ext.isDefined(this.initialConfig.minChars)){
  2770. this.minChars = 0;
  2771. }
  2772. }
  2773. },
  2774. // private
  2775. onRender : function(ct, position){
  2776. if(this.hiddenName && !Ext.isDefined(this.submitValue)){
  2777. this.submitValue = false;
  2778. }
  2779. Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
  2780. if(this.hiddenName){
  2781. this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName,
  2782. id: (this.hiddenId || Ext.id())}, 'before', true);
  2783. }
  2784. if(Ext.isGecko){
  2785. this.el.dom.setAttribute('autocomplete', 'off');
  2786. }
  2787. if(!this.lazyInit){
  2788. this.initList();
  2789. }else{
  2790. this.on('focus', this.initList, this, {single: true});
  2791. }
  2792. },
  2793. // private
  2794. initValue : function(){
  2795. Ext.form.ComboBox.superclass.initValue.call(this);
  2796. if(this.hiddenField){
  2797. this.hiddenField.value =
  2798. Ext.value(Ext.isDefined(this.hiddenValue) ? this.hiddenValue : this.value, '');
  2799. }
  2800. },
  2801. getParentZIndex : function(){
  2802. var zindex;
  2803. if (this.ownerCt){
  2804. this.findParentBy(function(ct){
  2805. zindex = parseInt(ct.getPositionEl().getStyle('z-index'), 10);
  2806. return !!zindex;
  2807. });
  2808. }
  2809. return zindex;
  2810. },
  2811. getZIndex : function(listParent){
  2812. listParent = listParent || Ext.getDom(this.getListParent() || Ext.getBody());
  2813. var zindex = parseInt(Ext.fly(listParent).getStyle('z-index'), 10);
  2814. if(!zindex){
  2815. zindex = this.getParentZIndex();
  2816. }
  2817. return (zindex || 12000) + 5;
  2818. },
  2819. // private
  2820. initList : function(){
  2821. if(!this.list){
  2822. var cls = 'x-combo-list',
  2823. listParent = Ext.getDom(this.getListParent() || Ext.getBody());
  2824. this.list = new Ext.Layer({
  2825. parentEl: listParent,
  2826. shadow: this.shadow,
  2827. cls: [cls, this.listClass].join(' '),
  2828. constrain:false,
  2829. zindex: this.getZIndex(listParent)
  2830. });
  2831. var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
  2832. this.list.setSize(lw, 0);
  2833. this.list.swallowEvent('mousewheel');
  2834. this.assetHeight = 0;
  2835. if(this.syncFont !== false){
  2836. this.list.setStyle('font-size', this.el.getStyle('font-size'));
  2837. }
  2838. if(this.title){
  2839. this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
  2840. this.assetHeight += this.header.getHeight();
  2841. }
  2842. this.innerList = this.list.createChild({cls:cls+'-inner'});
  2843. this.mon(this.innerList, 'mouseover', this.onViewOver, this);
  2844. this.mon(this.innerList, 'mousemove', this.onViewMove, this);
  2845. this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
  2846. if(this.pageSize){
  2847. this.footer = this.list.createChild({cls:cls+'-ft'});
  2848. this.pageTb = new Ext.PagingToolbar({
  2849. store: this.store,
  2850. pageSize: this.pageSize,
  2851. renderTo:this.footer
  2852. });
  2853. this.assetHeight += this.footer.getHeight();
  2854. }
  2855. if(!this.tpl){
  2856. /**
  2857. * @cfg {String/Ext.XTemplate} tpl <p>The template string, or {@link Ext.XTemplate} instance to
  2858. * use to display each item in the dropdown list. The dropdown list is displayed in a
  2859. * DataView. See {@link #view}.</p>
  2860. * <p>The default template string is:</p><pre><code>
  2861. '&lt;tpl for=".">&lt;div class="x-combo-list-item">{' + this.displayField + '}&lt;/div>&lt;/tpl>'
  2862. * </code></pre>
  2863. * <p>Override the default value to create custom UI layouts for items in the list.
  2864. * For example:</p><pre><code>
  2865. '&lt;tpl for=".">&lt;div ext:qtip="{state}. {nick}" class="x-combo-list-item">{state}&lt;/div>&lt;/tpl>'
  2866. * </code></pre>
  2867. * <p>The template <b>must</b> contain one or more substitution parameters using field
  2868. * names from the Combo's</b> {@link #store Store}. In the example above an
  2869. * <pre>ext:qtip</pre> attribute is added to display other fields from the Store.</p>
  2870. * <p>To preserve the default visual look of list items, add the CSS class name
  2871. * <pre>x-combo-list-item</pre> to the template's container element.</p>
  2872. * <p>Also see {@link #itemSelector} for additional details.</p>
  2873. */
  2874. this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>';
  2875. /**
  2876. * @cfg {String} itemSelector
  2877. * <p>A simple CSS selector (e.g. div.some-class or span:first-child) that will be
  2878. * used to determine what nodes the {@link #view Ext.DataView} which handles the dropdown
  2879. * display will be working with.</p>
  2880. * <p><b>Note</b>: this setting is <b>required</b> if a custom XTemplate has been
  2881. * specified in {@link #tpl} which assigns a class other than <pre>'x-combo-list-item'</pre>
  2882. * to dropdown list items</b>
  2883. */
  2884. }
  2885. /**
  2886. * The {@link Ext.DataView DataView} used to display the ComboBox's options.
  2887. * @type Ext.DataView
  2888. */
  2889. this.view = new Ext.DataView({
  2890. applyTo: this.innerList,
  2891. tpl: this.tpl,
  2892. singleSelect: true,
  2893. selectedClass: this.selectedClass,
  2894. itemSelector: this.itemSelector || '.' + cls + '-item',
  2895. emptyText: this.listEmptyText,
  2896. deferEmptyText: false
  2897. });
  2898. this.mon(this.view, {
  2899. containerclick : this.onViewClick,
  2900. click : this.onViewClick,
  2901. scope :this
  2902. });
  2903. this.bindStore(this.store, true);
  2904. if(this.resizable){
  2905. this.resizer = new Ext.Resizable(this.list, {
  2906. pinned:true, handles:'se'
  2907. });
  2908. this.mon(this.resizer, 'resize', function(r, w, h){
  2909. this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
  2910. this.listWidth = w;
  2911. this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
  2912. this.restrictHeight();
  2913. }, this);
  2914. this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
  2915. }
  2916. }
  2917. },
  2918. /**
  2919. * <p>Returns the element used to house this ComboBox's pop-up list. Defaults to the document body.</p>
  2920. * A custom implementation may be provided as a configuration option if the floating list needs to be rendered
  2921. * to a different Element. An example might be rendering the list inside a Menu so that clicking
  2922. * the list does not hide the Menu:<pre><code>
  2923. var store = new Ext.data.ArrayStore({
  2924. autoDestroy: true,
  2925. fields: ['initials', 'fullname'],
  2926. data : [
  2927. ['FF', 'Fred Flintstone'],
  2928. ['BR', 'Barney Rubble']
  2929. ]
  2930. });
  2931. var combo = new Ext.form.ComboBox({
  2932. store: store,
  2933. displayField: 'fullname',
  2934. emptyText: 'Select a name...',
  2935. forceSelection: true,
  2936. getListParent: function() {
  2937. return this.el.up('.x-menu');
  2938. },
  2939. iconCls: 'no-icon', //use iconCls if placing within menu to shift to right side of menu
  2940. mode: 'local',
  2941. selectOnFocus: true,
  2942. triggerAction: 'all',
  2943. typeAhead: true,
  2944. width: 135
  2945. });
  2946. var menu = new Ext.menu.Menu({
  2947. id: 'mainMenu',
  2948. items: [
  2949. combo // A Field in a Menu
  2950. ]
  2951. });
  2952. </code></pre>
  2953. */
  2954. getListParent : function() {
  2955. return document.body;
  2956. },
  2957. /**
  2958. * Returns the store associated with this combo.
  2959. * @return {Ext.data.Store} The store
  2960. */
  2961. getStore : function(){
  2962. return this.store;
  2963. },
  2964. // private
  2965. bindStore : function(store, initial){
  2966. if(this.store && !initial){
  2967. if(this.store !== store && this.store.autoDestroy){
  2968. this.store.destroy();
  2969. }else{
  2970. this.store.un('beforeload', this.onBeforeLoad, this);
  2971. this.store.un('load', this.onLoad, this);
  2972. this.store.un('exception', this.collapse, this);
  2973. }
  2974. if(!store){
  2975. this.store = null;
  2976. if(this.view){
  2977. this.view.bindStore(null);
  2978. }
  2979. if(this.pageTb){
  2980. this.pageTb.bindStore(null);
  2981. }
  2982. }
  2983. }
  2984. if(store){
  2985. if(!initial) {
  2986. this.lastQuery = null;
  2987. if(this.pageTb) {
  2988. this.pageTb.bindStore(store);
  2989. }
  2990. }
  2991. this.store = Ext.StoreMgr.lookup(store);
  2992. this.store.on({
  2993. scope: this,
  2994. beforeload: this.onBeforeLoad,
  2995. load: this.onLoad,
  2996. exception: this.collapse
  2997. });
  2998. if(this.view){
  2999. this.view.bindStore(store);
  3000. }
  3001. }
  3002. },
  3003. reset : function(){
  3004. if(this.clearFilterOnReset && this.mode == 'local'){
  3005. this.store.clearFilter();
  3006. }
  3007. Ext.form.ComboBox.superclass.reset.call(this);
  3008. },
  3009. // private
  3010. initEvents : function(){
  3011. Ext.form.ComboBox.superclass.initEvents.call(this);
  3012. /**
  3013. * @property keyNav
  3014. * @type Ext.KeyNav
  3015. * <p>A {@link Ext.KeyNav KeyNav} object which handles navigation keys for this ComboBox. This performs actions
  3016. * based on keystrokes typed when the input field is focused.</p>
  3017. * <p><b>After the ComboBox has been rendered</b>, you may override existing navigation key functionality,
  3018. * or add your own based upon key names as specified in the {@link Ext.KeyNav KeyNav} class.</p>
  3019. * <p>The function is executed in the scope (<code>this</code> reference of the ComboBox. Example:</p><pre><code>
  3020. myCombo.keyNav.esc = function(e) { // Override ESC handling function
  3021. this.collapse(); // Standard behaviour of Ext's ComboBox.
  3022. this.setValue(this.startValue); // We reset to starting value on ESC
  3023. };
  3024. myCombo.keyNav.tab = function() { // Override TAB handling function
  3025. this.onViewClick(false); // Select the currently highlighted row
  3026. };
  3027. </code></pre>
  3028. */
  3029. this.keyNav = new Ext.KeyNav(this.el, {
  3030. "up" : function(e){
  3031. this.inKeyMode = true;
  3032. this.selectPrev();
  3033. },
  3034. "down" : function(e){
  3035. if(!this.isExpanded()){
  3036. this.onTriggerClick();
  3037. }else{
  3038. this.inKeyMode = true;
  3039. this.selectNext();
  3040. }
  3041. },
  3042. "enter" : function(e){
  3043. this.onViewClick();
  3044. },
  3045. "esc" : function(e){
  3046. this.collapse();
  3047. },
  3048. "tab" : function(e){
  3049. if (this.forceSelection === true) {
  3050. this.collapse();
  3051. } else {
  3052. this.onViewClick(false);
  3053. }
  3054. return true;
  3055. },
  3056. scope : this,
  3057. doRelay : function(e, h, hname){
  3058. if(hname == 'down' || this.scope.isExpanded()){
  3059. // this MUST be called before ComboBox#fireKey()
  3060. var relay = Ext.KeyNav.prototype.doRelay.apply(this, arguments);
  3061. if((((Ext.isIE9 && Ext.isStrict) || Ext.isIE10p) || !Ext.isIE) && Ext.EventManager.useKeydown){
  3062. // call Combo#fireKey() for browsers which use keydown event (except IE)
  3063. this.scope.fireKey(e);
  3064. }
  3065. return relay;
  3066. }
  3067. return true;
  3068. },
  3069. forceKeyDown : true,
  3070. defaultEventAction: 'stopEvent'
  3071. });
  3072. this.queryDelay = Math.max(this.queryDelay || 10,
  3073. this.mode == 'local' ? 10 : 250);
  3074. this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
  3075. if(this.typeAhead){
  3076. this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
  3077. }
  3078. if(!this.enableKeyEvents){
  3079. this.mon(this.el, 'keyup', this.onKeyUp, this);
  3080. }
  3081. },
  3082. // private
  3083. onDestroy : function(){
  3084. if (this.dqTask){
  3085. this.dqTask.cancel();
  3086. this.dqTask = null;
  3087. }
  3088. this.bindStore(null);
  3089. Ext.destroy(
  3090. this.resizer,
  3091. this.view,
  3092. this.pageTb,
  3093. this.list
  3094. );
  3095. Ext.destroyMembers(this, 'hiddenField');
  3096. Ext.form.ComboBox.superclass.onDestroy.call(this);
  3097. },
  3098. // private
  3099. fireKey : function(e){
  3100. if (!this.isExpanded()) {
  3101. Ext.form.ComboBox.superclass.fireKey.call(this, e);
  3102. }
  3103. },
  3104. // private
  3105. onResize : function(w, h){
  3106. Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
  3107. if(!isNaN(w) && this.isVisible() && this.list){
  3108. this.doResize(w);
  3109. }else{
  3110. this.bufferSize = w;
  3111. }
  3112. },
  3113. doResize: function(w){
  3114. if(!Ext.isDefined(this.listWidth)){
  3115. var lw = Math.max(w, this.minListWidth);
  3116. this.list.setWidth(lw);
  3117. this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
  3118. }
  3119. },
  3120. // private
  3121. onEnable : function(){
  3122. Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
  3123. if(this.hiddenField){
  3124. this.hiddenField.disabled = false;
  3125. }
  3126. },
  3127. // private
  3128. onDisable : function(){
  3129. Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
  3130. if(this.hiddenField){
  3131. this.hiddenField.disabled = true;
  3132. }
  3133. },
  3134. // private
  3135. onBeforeLoad : function(){
  3136. if(!this.hasFocus){
  3137. return;
  3138. }
  3139. this.innerList.update(this.loadingText ?
  3140. '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
  3141. this.restrictHeight();
  3142. this.selectedIndex = -1;
  3143. },
  3144. // private
  3145. onLoad : function(){
  3146. if(!this.hasFocus){
  3147. return;
  3148. }
  3149. if(this.store.getCount() > 0 || this.listEmptyText){
  3150. this.expand();
  3151. this.restrictHeight();
  3152. if(this.lastQuery == this.allQuery){
  3153. if(this.editable){
  3154. this.el.dom.select();
  3155. }
  3156. if(this.autoSelect !== false && !this.selectByValue(this.value, true)){
  3157. this.select(0, true);
  3158. }
  3159. }else{
  3160. if(this.autoSelect !== false){
  3161. this.selectNext();
  3162. }
  3163. if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
  3164. this.taTask.delay(this.typeAheadDelay);
  3165. }
  3166. }
  3167. }else{
  3168. this.collapse();
  3169. }
  3170. },
  3171. // private
  3172. onTypeAhead : function(){
  3173. if(this.store.getCount() > 0){
  3174. var r = this.store.getAt(0);
  3175. var newValue = r.data[this.displayField];
  3176. var len = newValue.length;
  3177. var selStart = this.getRawValue().length;
  3178. if(selStart != len){
  3179. this.setRawValue(newValue);
  3180. this.selectText(selStart, newValue.length);
  3181. }
  3182. }
  3183. },
  3184. // private
  3185. assertValue : function(){
  3186. var val = this.getRawValue(),
  3187. rec;
  3188. if(this.valueField && Ext.isDefined(this.value)){
  3189. rec = this.findRecord(this.valueField, this.value);
  3190. }
  3191. if(!rec || rec.get(this.displayField) != val){
  3192. rec = this.findRecord(this.displayField, val);
  3193. }
  3194. if(!rec && this.forceSelection){
  3195. if(val.length > 0 && val != this.emptyText){
  3196. this.el.dom.value = Ext.value(this.lastSelectionText, '');
  3197. this.applyEmptyText();
  3198. }else{
  3199. this.clearValue();
  3200. }
  3201. }else{
  3202. if(rec && this.valueField){
  3203. // onSelect may have already set the value and by doing so
  3204. // set the display field properly. Let's not wipe out the
  3205. // valueField here by just sending the displayField.
  3206. if (this.value == val){
  3207. return;
  3208. }
  3209. val = rec.get(this.valueField || this.displayField);
  3210. }
  3211. this.setValue(val);
  3212. }
  3213. },
  3214. // private
  3215. onSelect : function(record, index){
  3216. if(this.fireEvent('beforeselect', this, record, index) !== false){
  3217. this.setValue(record.data[this.valueField || this.displayField]);
  3218. this.collapse();
  3219. this.fireEvent('select', this, record, index);
  3220. }
  3221. },
  3222. // inherit docs
  3223. getName: function(){
  3224. var hf = this.hiddenField;
  3225. return hf && hf.name ? hf.name : this.hiddenName || Ext.form.ComboBox.superclass.getName.call(this);
  3226. },
  3227. /**
  3228. * Returns the currently selected field value or empty string if no value is set.
  3229. * @return {String} value The selected value
  3230. */
  3231. getValue : function(){
  3232. if(this.valueField){
  3233. return Ext.isDefined(this.value) ? this.value : '';
  3234. }else{
  3235. return Ext.form.ComboBox.superclass.getValue.call(this);
  3236. }
  3237. },
  3238. /**
  3239. * Clears any text/value currently set in the field
  3240. */
  3241. clearValue : function(){
  3242. if(this.hiddenField){
  3243. this.hiddenField.value = '';
  3244. }
  3245. this.setRawValue('');
  3246. this.lastSelectionText = '';
  3247. this.applyEmptyText();
  3248. this.value = '';
  3249. },
  3250. /**
  3251. * Sets the specified value into the field. If the value finds a match, the corresponding record text
  3252. * will be displayed in the field. If the value does not match the data value of an existing item,
  3253. * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
  3254. * Otherwise the field will be blank (although the value will still be set).
  3255. * @param {String} value The value to match
  3256. * @return {Ext.form.Field} this
  3257. */
  3258. setValue : function(v){
  3259. var text = v;
  3260. if(this.valueField){
  3261. var r = this.findRecord(this.valueField, v);
  3262. if(r){
  3263. text = r.data[this.displayField];
  3264. }else if(Ext.isDefined(this.valueNotFoundText)){
  3265. text = this.valueNotFoundText;
  3266. }
  3267. }
  3268. this.lastSelectionText = text;
  3269. if(this.hiddenField){
  3270. this.hiddenField.value = Ext.value(v, '');
  3271. }
  3272. Ext.form.ComboBox.superclass.setValue.call(this, text);
  3273. this.value = v;
  3274. return this;
  3275. },
  3276. // private
  3277. findRecord : function(prop, value){
  3278. var record;
  3279. if(this.store.getCount() > 0){
  3280. this.store.each(function(r){
  3281. if(r.data[prop] == value){
  3282. record = r;
  3283. return false;
  3284. }
  3285. });
  3286. }
  3287. return record;
  3288. },
  3289. // private
  3290. onViewMove : function(e, t){
  3291. this.inKeyMode = false;
  3292. },
  3293. // private
  3294. onViewOver : function(e, t){
  3295. if(this.inKeyMode){ // prevent key nav and mouse over conflicts
  3296. return;
  3297. }
  3298. var item = this.view.findItemFromChild(t);
  3299. if(item){
  3300. var index = this.view.indexOf(item);
  3301. this.select(index, false);
  3302. }
  3303. },
  3304. // private
  3305. onViewClick : function(doFocus){
  3306. var index = this.view.getSelectedIndexes()[0],
  3307. s = this.store,
  3308. r = s.getAt(index);
  3309. if(r){
  3310. this.onSelect(r, index);
  3311. }else {
  3312. this.collapse();
  3313. }
  3314. if(doFocus !== false){
  3315. this.el.focus();
  3316. }
  3317. },
  3318. // private
  3319. restrictHeight : function(){
  3320. this.innerList.dom.style.height = '';
  3321. var inner = this.innerList.dom,
  3322. pad = this.list.getFrameWidth('tb') + (this.resizable ? this.handleHeight : 0) + this.assetHeight,
  3323. h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight),
  3324. ha = this.getPosition()[1]-Ext.getBody().getScroll().top,
  3325. hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height,
  3326. space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5;
  3327. h = Math.min(h, space, this.maxHeight);
  3328. this.innerList.setHeight(h);
  3329. this.list.beginUpdate();
  3330. this.list.setHeight(h+pad);
  3331. this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
  3332. this.list.endUpdate();
  3333. },
  3334. /**
  3335. * Returns true if the dropdown list is expanded, else false.
  3336. */
  3337. isExpanded : function(){
  3338. return this.list && this.list.isVisible();
  3339. },
  3340. /**
  3341. * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
  3342. * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
  3343. * @param {String} value The data value of the item to select
  3344. * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
  3345. * selected item if it is not currently in view (defaults to true)
  3346. * @return {Boolean} True if the value matched an item in the list, else false
  3347. */
  3348. selectByValue : function(v, scrollIntoView){
  3349. if(!Ext.isEmpty(v, true)){
  3350. var r = this.findRecord(this.valueField || this.displayField, v);
  3351. if(r){
  3352. this.select(this.store.indexOf(r), scrollIntoView);
  3353. return true;
  3354. }
  3355. }
  3356. return false;
  3357. },
  3358. /**
  3359. * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
  3360. * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
  3361. * @param {Number} index The zero-based index of the list item to select
  3362. * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
  3363. * selected item if it is not currently in view (defaults to true)
  3364. */
  3365. select : function(index, scrollIntoView){
  3366. this.selectedIndex = index;
  3367. this.view.select(index);
  3368. if(scrollIntoView !== false){
  3369. var el = this.view.getNode(index);
  3370. if(el){
  3371. this.innerList.scrollChildIntoView(el, false);
  3372. }
  3373. }
  3374. },
  3375. // private
  3376. selectNext : function(){
  3377. var ct = this.store.getCount();
  3378. if(ct > 0){
  3379. if(this.selectedIndex == -1){
  3380. this.select(0);
  3381. }else if(this.selectedIndex < ct-1){
  3382. this.select(this.selectedIndex+1);
  3383. }
  3384. }
  3385. },
  3386. // private
  3387. selectPrev : function(){
  3388. var ct = this.store.getCount();
  3389. if(ct > 0){
  3390. if(this.selectedIndex == -1){
  3391. this.select(0);
  3392. }else if(this.selectedIndex !== 0){
  3393. this.select(this.selectedIndex-1);
  3394. }
  3395. }
  3396. },
  3397. // private
  3398. onKeyUp : function(e){
  3399. var k = e.getKey();
  3400. if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
  3401. this.lastKey = k;
  3402. this.dqTask.delay(this.queryDelay);
  3403. }
  3404. Ext.form.ComboBox.superclass.onKeyUp.call(this, e);
  3405. },
  3406. // private
  3407. validateBlur : function(){
  3408. return !this.list || !this.list.isVisible();
  3409. },
  3410. // private
  3411. initQuery : function(){
  3412. this.doQuery(this.getRawValue());
  3413. },
  3414. // private
  3415. beforeBlur : function(){
  3416. this.assertValue();
  3417. },
  3418. // private
  3419. postBlur : function(){
  3420. Ext.form.ComboBox.superclass.postBlur.call(this);
  3421. this.collapse();
  3422. this.inKeyMode = false;
  3423. },
  3424. /**
  3425. * Execute a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
  3426. * query allowing the query action to be canceled if needed.
  3427. * @param {String} query The SQL query to execute
  3428. * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
  3429. * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
  3430. * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
  3431. */
  3432. doQuery : function(q, forceAll){
  3433. q = Ext.isEmpty(q) ? '' : q;
  3434. var qe = {
  3435. query: q,
  3436. forceAll: forceAll,
  3437. combo: this,
  3438. cancel:false
  3439. };
  3440. if(this.fireEvent('beforequery', qe)===false || qe.cancel){
  3441. return false;
  3442. }
  3443. q = qe.query;
  3444. forceAll = qe.forceAll;
  3445. if(forceAll === true || (q.length >= this.minChars)){
  3446. if(this.lastQuery !== q){
  3447. this.lastQuery = q;
  3448. if(this.mode == 'local'){
  3449. this.selectedIndex = -1;
  3450. if(forceAll){
  3451. this.store.clearFilter();
  3452. }else{
  3453. this.store.filter(this.displayField, q);
  3454. }
  3455. this.onLoad();
  3456. }else{
  3457. this.store.baseParams[this.queryParam] = q;
  3458. this.store.load({
  3459. params: this.getParams(q)
  3460. });
  3461. this.expand();
  3462. }
  3463. }else{
  3464. this.selectedIndex = -1;
  3465. this.onLoad();
  3466. }
  3467. }
  3468. },
  3469. // private
  3470. getParams : function(q){
  3471. var params = {},
  3472. paramNames = this.store.paramNames;
  3473. if(this.pageSize){
  3474. params[paramNames.start] = 0;
  3475. params[paramNames.limit] = this.pageSize;
  3476. }
  3477. return params;
  3478. },
  3479. /**
  3480. * Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
  3481. */
  3482. collapse : function(){
  3483. if(!this.isExpanded()){
  3484. return;
  3485. }
  3486. this.list.hide();
  3487. Ext.getDoc().un('mousewheel', this.collapseIf, this);
  3488. Ext.getDoc().un('mousedown', this.collapseIf, this);
  3489. this.fireEvent('collapse', this);
  3490. },
  3491. // private
  3492. collapseIf : function(e){
  3493. if(!this.isDestroyed && !e.within(this.wrap) && !e.within(this.list)){
  3494. this.collapse();
  3495. }
  3496. },
  3497. /**
  3498. * Expands the dropdown list if it is currently hidden. Fires the {@link #expand} event on completion.
  3499. */
  3500. expand : function(){
  3501. if(this.isExpanded() || !this.hasFocus){
  3502. return;
  3503. }
  3504. if(this.title || this.pageSize){
  3505. this.assetHeight = 0;
  3506. if(this.title){
  3507. this.assetHeight += this.header.getHeight();
  3508. }
  3509. if(this.pageSize){
  3510. this.assetHeight += this.footer.getHeight();
  3511. }
  3512. }
  3513. if(this.bufferSize){
  3514. this.doResize(this.bufferSize);
  3515. delete this.bufferSize;
  3516. }
  3517. this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
  3518. // zindex can change, re-check it and set it if necessary
  3519. this.list.setZIndex(this.getZIndex());
  3520. this.list.show();
  3521. if(Ext.isGecko2){
  3522. this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
  3523. }
  3524. this.mon(Ext.getDoc(), {
  3525. scope: this,
  3526. mousewheel: this.collapseIf,
  3527. mousedown: this.collapseIf
  3528. });
  3529. this.fireEvent('expand', this);
  3530. },
  3531. /**
  3532. * @method onTriggerClick
  3533. * @hide
  3534. */
  3535. // private
  3536. // Implements the default empty TriggerField.onTriggerClick function
  3537. onTriggerClick : function(){
  3538. if(this.readOnly || this.disabled){
  3539. return;
  3540. }
  3541. if(this.isExpanded()){
  3542. this.collapse();
  3543. this.el.focus();
  3544. }else {
  3545. this.onFocus({});
  3546. if(this.triggerAction == 'all') {
  3547. this.doQuery(this.allQuery, true);
  3548. } else {
  3549. this.doQuery(this.getRawValue());
  3550. }
  3551. this.el.focus();
  3552. }
  3553. }
  3554. /**
  3555. * @hide
  3556. * @method autoSize
  3557. */
  3558. /**
  3559. * @cfg {Boolean} grow @hide
  3560. */
  3561. /**
  3562. * @cfg {Number} growMin @hide
  3563. */
  3564. /**
  3565. * @cfg {Number} growMax @hide
  3566. */
  3567. });
  3568. Ext.reg('combo', Ext.form.ComboBox);
  3569. /**
  3570. * @class Ext.form.Checkbox
  3571. * @extends Ext.form.Field
  3572. * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
  3573. * @constructor
  3574. * Creates a new Checkbox
  3575. * @param {Object} config Configuration options
  3576. * @xtype checkbox
  3577. */
  3578. Ext.form.Checkbox = Ext.extend(Ext.form.Field, {
  3579. /**
  3580. * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
  3581. */
  3582. focusClass : undefined,
  3583. /**
  3584. * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to 'x-form-field')
  3585. */
  3586. fieldClass : 'x-form-field',
  3587. /**
  3588. * @cfg {Boolean} checked <tt>true</tt> if the checkbox should render initially checked (defaults to <tt>false</tt>)
  3589. */
  3590. checked : false,
  3591. /**
  3592. * @cfg {String} boxLabel The text that appears beside the checkbox
  3593. */
  3594. boxLabel: '&#160;',
  3595. /**
  3596. * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
  3597. * {tag: 'input', type: 'checkbox', autocomplete: 'off'})
  3598. */
  3599. defaultAutoCreate : { tag: 'input', type: 'checkbox', autocomplete: 'off'},
  3600. /**
  3601. * @cfg {String} inputValue The value that should go into the generated input element's value attribute
  3602. */
  3603. /**
  3604. * @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of
  3605. * handling the check event). The handler is passed the following parameters:
  3606. * <div class="mdetail-params"><ul>
  3607. * <li><b>checkbox</b> : Ext.form.Checkbox<div class="sub-desc">The Checkbox being toggled.</div></li>
  3608. * <li><b>checked</b> : Boolean<div class="sub-desc">The new checked state of the checkbox.</div></li>
  3609. * </ul></div>
  3610. */
  3611. /**
  3612. * @cfg {Object} scope An object to use as the scope ('this' reference) of the {@link #handler} function
  3613. * (defaults to this Checkbox).
  3614. */
  3615. // private
  3616. actionMode : 'wrap',
  3617. // private
  3618. initComponent : function(){
  3619. Ext.form.Checkbox.superclass.initComponent.call(this);
  3620. this.addEvents(
  3621. /**
  3622. * @event check
  3623. * Fires when the checkbox is checked or unchecked.
  3624. * @param {Ext.form.Checkbox} this This checkbox
  3625. * @param {Boolean} checked The new checked value
  3626. */
  3627. 'check'
  3628. );
  3629. },
  3630. // private
  3631. onResize : function(){
  3632. Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
  3633. if(!this.boxLabel && !this.fieldLabel){
  3634. this.el.alignTo(this.wrap, 'c-c');
  3635. }
  3636. },
  3637. // private
  3638. initEvents : function(){
  3639. Ext.form.Checkbox.superclass.initEvents.call(this);
  3640. this.mon(this.el, {
  3641. scope: this,
  3642. click: this.onClick,
  3643. change: this.onClick
  3644. });
  3645. },
  3646. /**
  3647. * @hide
  3648. * Overridden and disabled. The editor element does not support standard valid/invalid marking.
  3649. * @method
  3650. */
  3651. markInvalid : Ext.emptyFn,
  3652. /**
  3653. * @hide
  3654. * Overridden and disabled. The editor element does not support standard valid/invalid marking.
  3655. * @method
  3656. */
  3657. clearInvalid : Ext.emptyFn,
  3658. // private
  3659. onRender : function(ct, position){
  3660. Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
  3661. if(this.inputValue !== undefined){
  3662. this.el.dom.value = this.inputValue;
  3663. }
  3664. this.wrap = this.el.wrap({cls: 'x-form-check-wrap'});
  3665. if(this.boxLabel){
  3666. this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
  3667. }
  3668. if(this.checked){
  3669. this.setValue(true);
  3670. }else{
  3671. this.checked = this.el.dom.checked;
  3672. }
  3673. // Need to repaint for IE, otherwise positioning is broken
  3674. if (Ext.isIEQuirks) {
  3675. this.wrap.repaint();
  3676. }
  3677. this.resizeEl = this.positionEl = this.wrap;
  3678. },
  3679. // private
  3680. onDestroy : function(){
  3681. Ext.destroy(this.wrap);
  3682. Ext.form.Checkbox.superclass.onDestroy.call(this);
  3683. },
  3684. // private
  3685. initValue : function() {
  3686. this.originalValue = this.getValue();
  3687. },
  3688. /**
  3689. * Returns the checked state of the checkbox.
  3690. * @return {Boolean} True if checked, else false
  3691. */
  3692. getValue : function(){
  3693. if(this.rendered){
  3694. return this.el.dom.checked;
  3695. }
  3696. return this.checked;
  3697. },
  3698. // private
  3699. onClick : function(){
  3700. if(this.el.dom.checked != this.checked){
  3701. this.setValue(this.el.dom.checked);
  3702. }
  3703. },
  3704. /**
  3705. * Sets the checked state of the checkbox, fires the 'check' event, and calls a
  3706. * <code>{@link #handler}</code> (if configured).
  3707. * @param {Boolean/String} checked The following values will check the checkbox:
  3708. * <code>true, 'true', '1', or 'on'</code>. Any other value will uncheck the checkbox.
  3709. * @return {Ext.form.Field} this
  3710. */
  3711. setValue : function(v){
  3712. var checked = this.checked,
  3713. inputVal = this.inputValue;
  3714. if (v === false) {
  3715. this.checked = false;
  3716. } else {
  3717. this.checked = (v === true || v === 'true' || v == '1' || (inputVal ? v == inputVal : String(v).toLowerCase() == 'on'));
  3718. }
  3719. if(this.rendered){
  3720. this.el.dom.checked = this.checked;
  3721. this.el.dom.defaultChecked = this.checked;
  3722. }
  3723. if(checked != this.checked){
  3724. this.fireEvent('check', this, this.checked);
  3725. if(this.handler){
  3726. this.handler.call(this.scope || this, this, this.checked);
  3727. }
  3728. }
  3729. return this;
  3730. }
  3731. });
  3732. Ext.reg('checkbox', Ext.form.Checkbox);
  3733. /**
  3734. * @class Ext.form.CheckboxGroup
  3735. * @extends Ext.form.Field
  3736. * <p>A grouping container for {@link Ext.form.Checkbox} controls.</p>
  3737. * <p>Sample usage:</p>
  3738. * <pre><code>
  3739. var myCheckboxGroup = new Ext.form.CheckboxGroup({
  3740. id:'myGroup',
  3741. xtype: 'checkboxgroup',
  3742. fieldLabel: 'Single Column',
  3743. itemCls: 'x-check-group-alt',
  3744. // Put all controls in a single column with width 100%
  3745. columns: 1,
  3746. items: [
  3747. {boxLabel: 'Item 1', name: 'cb-col-1'},
  3748. {boxLabel: 'Item 2', name: 'cb-col-2', checked: true},
  3749. {boxLabel: 'Item 3', name: 'cb-col-3'}
  3750. ]
  3751. });
  3752. * </code></pre>
  3753. * @constructor
  3754. * Creates a new CheckboxGroup
  3755. * @param {Object} config Configuration options
  3756. * @xtype checkboxgroup
  3757. */
  3758. Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, {
  3759. /**
  3760. * @cfg {Array} items An Array of {@link Ext.form.Checkbox Checkbox}es or Checkbox config objects
  3761. * to arrange in the group.
  3762. */
  3763. /**
  3764. * @cfg {String/Number/Array} columns Specifies the number of columns to use when displaying grouped
  3765. * checkbox/radio controls using automatic layout. This config can take several types of values:
  3766. * <ul><li><b>'auto'</b> : <p class="sub-desc">The controls will be rendered one per column on one row and the width
  3767. * of each column will be evenly distributed based on the width of the overall field container. This is the default.</p></li>
  3768. * <li><b>Number</b> : <p class="sub-desc">If you specific a number (e.g., 3) that number of columns will be
  3769. * created and the contained controls will be automatically distributed based on the value of {@link #vertical}.</p></li>
  3770. * <li><b>Array</b> : Object<p class="sub-desc">You can also specify an array of column widths, mixing integer
  3771. * (fixed width) and float (percentage width) values as needed (e.g., [100, .25, .75]). Any integer values will
  3772. * be rendered first, then any float values will be calculated as a percentage of the remaining space. Float
  3773. * values do not have to add up to 1 (100%) although if you want the controls to take up the entire field
  3774. * container you should do so.</p></li></ul>
  3775. */
  3776. columns : 'auto',
  3777. /**
  3778. * @cfg {Boolean} vertical True to distribute contained controls across columns, completely filling each column
  3779. * top to bottom before starting on the next column. The number of controls in each column will be automatically
  3780. * calculated to keep columns as even as possible. The default value is false, so that controls will be added
  3781. * to columns one at a time, completely filling each row left to right before starting on the next row.
  3782. */
  3783. vertical : false,
  3784. /**
  3785. * @cfg {Boolean} allowBlank False to validate that at least one item in the group is checked (defaults to true).
  3786. * If no items are selected at validation time, {@link @blankText} will be used as the error text.
  3787. */
  3788. allowBlank : true,
  3789. /**
  3790. * @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails (defaults to "You must
  3791. * select at least one item in this group")
  3792. */
  3793. blankText : "You must select at least one item in this group",
  3794. // private
  3795. defaultType : 'checkbox',
  3796. // private
  3797. groupCls : 'x-form-check-group',
  3798. // private
  3799. initComponent: function(){
  3800. this.addEvents(
  3801. /**
  3802. * @event change
  3803. * Fires when the state of a child checkbox changes.
  3804. * @param {Ext.form.CheckboxGroup} this
  3805. * @param {Array} checked An array containing the checked boxes.
  3806. */
  3807. 'change'
  3808. );
  3809. this.on('change', this.validate, this);
  3810. Ext.form.CheckboxGroup.superclass.initComponent.call(this);
  3811. },
  3812. // private
  3813. onRender : function(ct, position){
  3814. if(!this.el){
  3815. var panelCfg = {
  3816. autoEl: {
  3817. id: this.id
  3818. },
  3819. cls: this.groupCls,
  3820. layout: 'column',
  3821. renderTo: ct,
  3822. bufferResize: false // Default this to false, since it doesn't really have a proper ownerCt.
  3823. };
  3824. var colCfg = {
  3825. xtype: 'container',
  3826. defaultType: this.defaultType,
  3827. layout: 'form',
  3828. defaults: {
  3829. hideLabel: true,
  3830. anchor: '100%'
  3831. }
  3832. };
  3833. if(this.items[0].items){
  3834. // The container has standard ColumnLayout configs, so pass them in directly
  3835. Ext.apply(panelCfg, {
  3836. layoutConfig: {columns: this.items.length},
  3837. defaults: this.defaults,
  3838. items: this.items
  3839. });
  3840. for(var i=0, len=this.items.length; i<len; i++){
  3841. Ext.applyIf(this.items[i], colCfg);
  3842. }
  3843. }else{
  3844. // The container has field item configs, so we have to generate the column
  3845. // panels first then move the items into the columns as needed.
  3846. var numCols, cols = [];
  3847. if(typeof this.columns == 'string'){ // 'auto' so create a col per item
  3848. this.columns = this.items.length;
  3849. }
  3850. if(!Ext.isArray(this.columns)){
  3851. var cs = [];
  3852. for(var i=0; i<this.columns; i++){
  3853. cs.push((100/this.columns)*.01); // distribute by even %
  3854. }
  3855. this.columns = cs;
  3856. }
  3857. numCols = this.columns.length;
  3858. // Generate the column configs with the correct width setting
  3859. for(var i=0; i<numCols; i++){
  3860. var cc = Ext.apply({items:[]}, colCfg);
  3861. cc[this.columns[i] <= 1 ? 'columnWidth' : 'width'] = this.columns[i];
  3862. if(this.defaults){
  3863. cc.defaults = Ext.apply(cc.defaults || {}, this.defaults);
  3864. }
  3865. cols.push(cc);
  3866. };
  3867. // Distribute the original items into the columns
  3868. if(this.vertical){
  3869. var rows = Math.ceil(this.items.length / numCols), ri = 0;
  3870. for(var i=0, len=this.items.length; i<len; i++){
  3871. if(i>0 && i%rows==0){
  3872. ri++;
  3873. }
  3874. if(this.items[i].fieldLabel){
  3875. this.items[i].hideLabel = false;
  3876. }
  3877. cols[ri].items.push(this.items[i]);
  3878. };
  3879. }else{
  3880. for(var i=0, len=this.items.length; i<len; i++){
  3881. var ci = i % numCols;
  3882. if(this.items[i].fieldLabel){
  3883. this.items[i].hideLabel = false;
  3884. }
  3885. cols[ci].items.push(this.items[i]);
  3886. };
  3887. }
  3888. Ext.apply(panelCfg, {
  3889. layoutConfig: {columns: numCols},
  3890. items: cols
  3891. });
  3892. }
  3893. this.panel = new Ext.Container(panelCfg);
  3894. this.panel.ownerCt = this;
  3895. this.el = this.panel.getEl();
  3896. if(this.forId && this.itemCls){
  3897. var l = this.el.up(this.itemCls).child('label', true);
  3898. if(l){
  3899. l.setAttribute('htmlFor', this.forId);
  3900. }
  3901. }
  3902. var fields = this.panel.findBy(function(c){
  3903. return c.isFormField;
  3904. }, this);
  3905. this.items = new Ext.util.MixedCollection();
  3906. this.items.addAll(fields);
  3907. }
  3908. Ext.form.CheckboxGroup.superclass.onRender.call(this, ct, position);
  3909. },
  3910. initValue : function(){
  3911. if(this.value){
  3912. this.setValue.apply(this, this.buffered ? this.value : [this.value]);
  3913. delete this.buffered;
  3914. delete this.value;
  3915. }
  3916. },
  3917. afterRender : function(){
  3918. Ext.form.CheckboxGroup.superclass.afterRender.call(this);
  3919. this.eachItem(function(item){
  3920. item.on('check', this.fireChecked, this);
  3921. item.inGroup = true;
  3922. });
  3923. },
  3924. // private
  3925. doLayout: function(){
  3926. //ugly method required to layout hidden items
  3927. if(this.rendered){
  3928. this.panel.forceLayout = this.ownerCt.forceLayout;
  3929. this.panel.doLayout();
  3930. }
  3931. },
  3932. // private
  3933. fireChecked: function(){
  3934. var arr = [];
  3935. this.eachItem(function(item){
  3936. if(item.checked){
  3937. arr.push(item);
  3938. }
  3939. });
  3940. this.fireEvent('change', this, arr);
  3941. },
  3942. /**
  3943. * Runs CheckboxGroup's validations and returns an array of any errors. The only error by default
  3944. * is if allowBlank is set to true and no items are checked.
  3945. * @return {Array} Array of all validation errors
  3946. */
  3947. getErrors: function() {
  3948. var errors = Ext.form.CheckboxGroup.superclass.getErrors.apply(this, arguments);
  3949. if (!this.allowBlank) {
  3950. var blank = true;
  3951. this.eachItem(function(f){
  3952. if (f.checked) {
  3953. return (blank = false);
  3954. }
  3955. });
  3956. if (blank) errors.push(this.blankText);
  3957. }
  3958. return errors;
  3959. },
  3960. // private
  3961. isDirty: function(){
  3962. //override the behaviour to check sub items.
  3963. if (this.disabled || !this.rendered) {
  3964. return false;
  3965. }
  3966. var dirty = false;
  3967. this.eachItem(function(item){
  3968. if(item.isDirty()){
  3969. dirty = true;
  3970. return false;
  3971. }
  3972. });
  3973. return dirty;
  3974. },
  3975. // private
  3976. setReadOnly : function(readOnly){
  3977. if(this.rendered){
  3978. this.eachItem(function(item){
  3979. item.setReadOnly(readOnly);
  3980. });
  3981. }
  3982. this.readOnly = readOnly;
  3983. },
  3984. // private
  3985. onDisable : function(){
  3986. this.eachItem(function(item){
  3987. item.disable();
  3988. });
  3989. },
  3990. // private
  3991. onEnable : function(){
  3992. this.eachItem(function(item){
  3993. item.enable();
  3994. });
  3995. },
  3996. // private
  3997. onResize : function(w, h){
  3998. this.panel.setSize(w, h);
  3999. this.panel.doLayout();
  4000. },
  4001. // inherit docs from Field
  4002. reset : function(){
  4003. if (this.originalValue) {
  4004. // Clear all items
  4005. this.eachItem(function(c){
  4006. if(c.setValue){
  4007. c.setValue(false);
  4008. c.originalValue = c.getValue();
  4009. }
  4010. });
  4011. // Set items stored in originalValue, ugly - set a flag to reset the originalValue
  4012. // during the horrible onSetValue. This will allow trackResetOnLoad to function.
  4013. this.resetOriginal = true;
  4014. this.setValue(this.originalValue);
  4015. delete this.resetOriginal;
  4016. } else {
  4017. this.eachItem(function(c){
  4018. if(c.reset){
  4019. c.reset();
  4020. }
  4021. });
  4022. }
  4023. // Defer the clearInvalid so if BaseForm's collection is being iterated it will be called AFTER it is complete.
  4024. // Important because reset is being called on both the group and the individual items.
  4025. (function() {
  4026. this.clearInvalid();
  4027. }).defer(50, this);
  4028. },
  4029. /**
  4030. * {@link Ext.form.Checkbox#setValue Set the value(s)} of an item or items
  4031. * in the group. Examples illustrating how this method may be called:
  4032. * <pre><code>
  4033. // call with name and value
  4034. myCheckboxGroup.setValue('cb-col-1', true);
  4035. // call with an array of boolean values
  4036. myCheckboxGroup.setValue([true, false, false]);
  4037. // call with an object literal specifying item:value pairs
  4038. myCheckboxGroup.setValue({
  4039. 'cb-col-2': false,
  4040. 'cb-col-3': true
  4041. });
  4042. // use comma separated string to set items with name to true (checked)
  4043. myCheckboxGroup.setValue('cb-col-1,cb-col-3');
  4044. * </code></pre>
  4045. * See {@link Ext.form.Checkbox#setValue} for additional information.
  4046. * @param {Mixed} id The checkbox to check, or as described by example shown.
  4047. * @param {Boolean} value (optional) The value to set the item.
  4048. * @return {Ext.form.CheckboxGroup} this
  4049. */
  4050. setValue: function(){
  4051. if(this.rendered){
  4052. this.onSetValue.apply(this, arguments);
  4053. }else{
  4054. this.buffered = true;
  4055. this.value = arguments;
  4056. }
  4057. return this;
  4058. },
  4059. /**
  4060. * @private
  4061. * Sets the values of one or more of the items within the CheckboxGroup
  4062. * @param {String|Array|Object} id Can take multiple forms. Can be optionally:
  4063. * <ul>
  4064. * <li>An ID string to be used with a second argument</li>
  4065. * <li>An array of the form ['some', 'list', 'of', 'ids', 'to', 'mark', 'checked']</li>
  4066. * <li>An array in the form [true, true, false, true, false] etc, where each item relates to the check status of
  4067. * the checkbox at the same index</li>
  4068. * <li>An object containing ids of the checkboxes as keys and check values as properties</li>
  4069. * </ul>
  4070. * @param {String} value The value to set the field to if the first argument was a string
  4071. */
  4072. onSetValue: function(id, value){
  4073. if(arguments.length == 1){
  4074. if(Ext.isArray(id)){
  4075. Ext.each(id, function(val, idx){
  4076. if (Ext.isObject(val) && val.setValue){ // array of checkbox components to be checked
  4077. val.setValue(true);
  4078. if (this.resetOriginal === true) {
  4079. val.originalValue = val.getValue();
  4080. }
  4081. } else { // an array of boolean values
  4082. var item = this.items.itemAt(idx);
  4083. if(item){
  4084. item.setValue(val);
  4085. }
  4086. }
  4087. }, this);
  4088. }else if(Ext.isObject(id)){
  4089. // set of name/value pairs
  4090. for(var i in id){
  4091. var f = this.getBox(i);
  4092. if(f){
  4093. f.setValue(id[i]);
  4094. }
  4095. }
  4096. }else{
  4097. this.setValueForItem(id);
  4098. }
  4099. }else{
  4100. var f = this.getBox(id);
  4101. if(f){
  4102. f.setValue(value);
  4103. }
  4104. }
  4105. },
  4106. // private
  4107. beforeDestroy: function(){
  4108. Ext.destroy(this.panel);
  4109. if (!this.rendered) {
  4110. Ext.destroy(this.items);
  4111. }
  4112. Ext.form.CheckboxGroup.superclass.beforeDestroy.call(this);
  4113. },
  4114. setValueForItem : function(val){
  4115. val = String(val).split(',');
  4116. this.eachItem(function(item){
  4117. if(val.indexOf(item.inputValue)> -1){
  4118. item.setValue(true);
  4119. }
  4120. });
  4121. },
  4122. // private
  4123. getBox : function(id){
  4124. var box = null;
  4125. this.eachItem(function(f){
  4126. if(id == f || f.dataIndex == id || f.id == id || f.getName() == id){
  4127. box = f;
  4128. return false;
  4129. }
  4130. });
  4131. return box;
  4132. },
  4133. /**
  4134. * Gets an array of the selected {@link Ext.form.Checkbox} in the group.
  4135. * @return {Array} An array of the selected checkboxes.
  4136. */
  4137. getValue : function(){
  4138. var out = [];
  4139. this.eachItem(function(item){
  4140. if(item.checked){
  4141. out.push(item);
  4142. }
  4143. });
  4144. return out;
  4145. },
  4146. /**
  4147. * @private
  4148. * Convenience function which passes the given function to every item in the composite
  4149. * @param {Function} fn The function to call
  4150. * @param {Object} scope Optional scope object
  4151. */
  4152. eachItem: function(fn, scope) {
  4153. if(this.items && this.items.each){
  4154. this.items.each(fn, scope || this);
  4155. }
  4156. },
  4157. /**
  4158. * @cfg {String} name
  4159. * @hide
  4160. */
  4161. /**
  4162. * @method getRawValue
  4163. * @hide
  4164. */
  4165. getRawValue : Ext.emptyFn,
  4166. /**
  4167. * @method setRawValue
  4168. * @hide
  4169. */
  4170. setRawValue : Ext.emptyFn
  4171. });
  4172. Ext.reg('checkboxgroup', Ext.form.CheckboxGroup);
  4173. /**
  4174. * @class Ext.form.CompositeField
  4175. * @extends Ext.form.Field
  4176. * Composite field allowing a number of form Fields to be rendered on the same row. The fields are rendered
  4177. * using an hbox layout internally, so all of the normal HBox layout config items are available. Example usage:
  4178. * <pre>
  4179. {
  4180. xtype: 'compositefield',
  4181. labelWidth: 120
  4182. items: [
  4183. {
  4184. xtype : 'textfield',
  4185. fieldLabel: 'Title',
  4186. width : 20
  4187. },
  4188. {
  4189. xtype : 'textfield',
  4190. fieldLabel: 'First',
  4191. flex : 1
  4192. },
  4193. {
  4194. xtype : 'textfield',
  4195. fieldLabel: 'Last',
  4196. flex : 1
  4197. }
  4198. ]
  4199. }
  4200. * </pre>
  4201. * In the example above the composite's fieldLabel will be set to 'Title, First, Last' as it groups the fieldLabels
  4202. * of each of its children. This can be overridden by setting a fieldLabel on the compositefield itself:
  4203. * <pre>
  4204. {
  4205. xtype: 'compositefield',
  4206. fieldLabel: 'Custom label',
  4207. items: [...]
  4208. }
  4209. * </pre>
  4210. * Any Ext.form.* component can be placed inside a composite field.
  4211. */
  4212. Ext.form.CompositeField = Ext.extend(Ext.form.Field, {
  4213. /**
  4214. * @property defaultMargins
  4215. * @type String
  4216. * The margins to apply by default to each field in the composite
  4217. */
  4218. defaultMargins: '0 5 0 0',
  4219. /**
  4220. * @property skipLastItemMargin
  4221. * @type Boolean
  4222. * If true, the defaultMargins are not applied to the last item in the composite field set (defaults to true)
  4223. */
  4224. skipLastItemMargin: true,
  4225. /**
  4226. * @property isComposite
  4227. * @type Boolean
  4228. * Signifies that this is a Composite field
  4229. */
  4230. isComposite: true,
  4231. /**
  4232. * @property combineErrors
  4233. * @type Boolean
  4234. * True to combine errors from the individual fields into a single error message at the CompositeField level (defaults to true)
  4235. */
  4236. combineErrors: true,
  4237. /**
  4238. * @cfg {String} labelConnector The string to use when joining segments of the built label together (defaults to ', ')
  4239. */
  4240. labelConnector: ', ',
  4241. /**
  4242. * @cfg {Object} defaults Any default properties to assign to the child fields.
  4243. */
  4244. //inherit docs
  4245. //Builds the composite field label
  4246. initComponent: function() {
  4247. var labels = [],
  4248. items = this.items,
  4249. item;
  4250. for (var i=0, j = items.length; i < j; i++) {
  4251. item = items[i];
  4252. if (!Ext.isEmpty(item.ref)){
  4253. item.ref = '../' + item.ref;
  4254. }
  4255. labels.push(item.fieldLabel);
  4256. //apply any defaults
  4257. Ext.applyIf(item, this.defaults);
  4258. //apply default margins to each item except the last
  4259. if (!(i == j - 1 && this.skipLastItemMargin)) {
  4260. Ext.applyIf(item, {margins: this.defaultMargins});
  4261. }
  4262. }
  4263. this.fieldLabel = this.fieldLabel || this.buildLabel(labels);
  4264. /**
  4265. * @property fieldErrors
  4266. * @type Ext.util.MixedCollection
  4267. * MixedCollection of current errors on the Composite's subfields. This is used internally to track when
  4268. * to show and hide error messages at the Composite level. Listeners are attached to the MixedCollection's
  4269. * add, remove and replace events to update the error icon in the UI as errors are added or removed.
  4270. */
  4271. this.fieldErrors = new Ext.util.MixedCollection(true, function(item) {
  4272. return item.field;
  4273. });
  4274. this.fieldErrors.on({
  4275. scope : this,
  4276. add : this.updateInvalidMark,
  4277. remove : this.updateInvalidMark,
  4278. replace: this.updateInvalidMark
  4279. });
  4280. Ext.form.CompositeField.superclass.initComponent.apply(this, arguments);
  4281. this.innerCt = new Ext.Container({
  4282. layout : 'hbox',
  4283. items : this.items,
  4284. cls : 'x-form-composite',
  4285. defaultMargins: '0 3 0 0',
  4286. ownerCt: this
  4287. });
  4288. delete this.innerCt.ownerCt;
  4289. var fields = this.innerCt.findBy(function(c) {
  4290. return c.isFormField;
  4291. }, this);
  4292. /**
  4293. * @property items
  4294. * @type Ext.util.MixedCollection
  4295. * Internal collection of all of the subfields in this Composite
  4296. */
  4297. this.items = new Ext.util.MixedCollection();
  4298. this.items.addAll(fields);
  4299. },
  4300. /**
  4301. * @private
  4302. * Creates an internal container using hbox and renders the fields to it
  4303. */
  4304. onRender: function(ct, position) {
  4305. if (!this.el) {
  4306. /**
  4307. * @property innerCt
  4308. * @type Ext.Container
  4309. * A container configured with hbox layout which is responsible for laying out the subfields
  4310. */
  4311. var innerCt = this.innerCt;
  4312. innerCt.render(ct);
  4313. this.innerCt.ownerCt = this;
  4314. this.el = innerCt.getEl();
  4315. //if we're combining subfield errors into a single message, override the markInvalid and clearInvalid
  4316. //methods of each subfield and show them at the Composite level instead
  4317. if (this.combineErrors) {
  4318. this.eachItem(function(field) {
  4319. Ext.apply(field, {
  4320. markInvalid : this.onFieldMarkInvalid.createDelegate(this, [field], 0),
  4321. clearInvalid: this.onFieldClearInvalid.createDelegate(this, [field], 0)
  4322. });
  4323. });
  4324. }
  4325. //set the label 'for' to the first item
  4326. var l = this.el.parent().parent().child('label', true);
  4327. if (l) {
  4328. l.setAttribute('for', this.items.items[0].id);
  4329. }
  4330. }
  4331. Ext.form.CompositeField.superclass.onRender.apply(this, arguments);
  4332. },
  4333. /**
  4334. * Called if combineErrors is true and a subfield's markInvalid method is called.
  4335. * By default this just adds the subfield's error to the internal fieldErrors MixedCollection
  4336. * @param {Ext.form.Field} field The field that was marked invalid
  4337. * @param {String} message The error message
  4338. */
  4339. onFieldMarkInvalid: function(field, message) {
  4340. var name = field.getName(),
  4341. error = {
  4342. field: name,
  4343. errorName: field.fieldLabel || name,
  4344. error: message
  4345. };
  4346. this.fieldErrors.replace(name, error);
  4347. if (!field.preventMark) {
  4348. field.el.addClass(field.invalidClass);
  4349. }
  4350. },
  4351. /**
  4352. * Called if combineErrors is true and a subfield's clearInvalid method is called.
  4353. * By default this just updates the internal fieldErrors MixedCollection.
  4354. * @param {Ext.form.Field} field The field that was marked invalid
  4355. */
  4356. onFieldClearInvalid: function(field) {
  4357. this.fieldErrors.removeKey(field.getName());
  4358. field.el.removeClass(field.invalidClass);
  4359. },
  4360. /**
  4361. * @private
  4362. * Called after a subfield is marked valid or invalid, this checks to see if any of the subfields are
  4363. * currently invalid. If any subfields are invalid it builds a combined error message marks the composite
  4364. * invalid, otherwise clearInvalid is called
  4365. */
  4366. updateInvalidMark: function() {
  4367. var ieStrict = Ext.isIE6 && Ext.isStrict;
  4368. if (this.fieldErrors.length == 0) {
  4369. this.clearInvalid();
  4370. //IE6 in strict mode has a layout bug when using 'under' as the error message target. This fixes it
  4371. if (ieStrict) {
  4372. this.clearInvalid.defer(50, this);
  4373. }
  4374. } else {
  4375. var message = this.buildCombinedErrorMessage(this.fieldErrors.items);
  4376. this.sortErrors();
  4377. this.markInvalid(message);
  4378. //IE6 in strict mode has a layout bug when using 'under' as the error message target. This fixes it
  4379. if (ieStrict) {
  4380. this.markInvalid(message);
  4381. }
  4382. }
  4383. },
  4384. /**
  4385. * Performs validation checks on each subfield and returns false if any of them fail validation.
  4386. * @return {Boolean} False if any subfield failed validation
  4387. */
  4388. validateValue: function(value, preventMark) {
  4389. var valid = true;
  4390. this.eachItem(function(field) {
  4391. if (!field.isValid(preventMark)) {
  4392. valid = false;
  4393. }
  4394. });
  4395. return valid;
  4396. },
  4397. /**
  4398. * Takes an object containing error messages for contained fields, returning a combined error
  4399. * string (defaults to just placing each item on a new line). This can be overridden to provide
  4400. * custom combined error message handling.
  4401. * @param {Array} errors Array of errors in format: [{field: 'title', error: 'some error'}]
  4402. * @return {String} The combined error message
  4403. */
  4404. buildCombinedErrorMessage: function(errors) {
  4405. var combined = [],
  4406. error;
  4407. for (var i = 0, j = errors.length; i < j; i++) {
  4408. error = errors[i];
  4409. combined.push(String.format("{0}: {1}", error.errorName, error.error));
  4410. }
  4411. return combined.join("<br />");
  4412. },
  4413. /**
  4414. * Sorts the internal fieldErrors MixedCollection by the order in which the fields are defined.
  4415. * This is called before displaying errors to ensure that the errors are presented in the expected order.
  4416. * This function can be overridden to provide a custom sorting order if needed.
  4417. */
  4418. sortErrors: function() {
  4419. var fields = this.items;
  4420. this.fieldErrors.sort("ASC", function(a, b) {
  4421. var findByName = function(key) {
  4422. return function(field) {
  4423. return field.getName() == key;
  4424. };
  4425. };
  4426. var aIndex = fields.findIndexBy(findByName(a.field)),
  4427. bIndex = fields.findIndexBy(findByName(b.field));
  4428. return aIndex < bIndex ? -1 : 1;
  4429. });
  4430. },
  4431. /**
  4432. * Resets each field in the composite to their previous value
  4433. */
  4434. reset: function() {
  4435. this.eachItem(function(item) {
  4436. item.reset();
  4437. });
  4438. // Defer the clearInvalid so if BaseForm's collection is being iterated it will be called AFTER it is complete.
  4439. // Important because reset is being called on both the group and the individual items.
  4440. (function() {
  4441. this.clearInvalid();
  4442. }).defer(50, this);
  4443. },
  4444. /**
  4445. * Calls clearInvalid on all child fields. This is a convenience function and should not often need to be called
  4446. * as fields usually take care of clearing themselves
  4447. */
  4448. clearInvalidChildren: function() {
  4449. this.eachItem(function(item) {
  4450. item.clearInvalid();
  4451. });
  4452. },
  4453. /**
  4454. * Builds a label string from an array of subfield labels.
  4455. * By default this just joins the labels together with a comma
  4456. * @param {Array} segments Array of each of the labels in the composite field's subfields
  4457. * @return {String} The built label
  4458. */
  4459. buildLabel: function(segments) {
  4460. return Ext.clean(segments).join(this.labelConnector);
  4461. },
  4462. /**
  4463. * Checks each field in the composite and returns true if any is dirty
  4464. * @return {Boolean} True if any field is dirty
  4465. */
  4466. isDirty: function(){
  4467. //override the behaviour to check sub items.
  4468. if (this.disabled || !this.rendered) {
  4469. return false;
  4470. }
  4471. var dirty = false;
  4472. this.eachItem(function(item){
  4473. if(item.isDirty()){
  4474. dirty = true;
  4475. return false;
  4476. }
  4477. });
  4478. return dirty;
  4479. },
  4480. /**
  4481. * @private
  4482. * Convenience function which passes the given function to every item in the composite
  4483. * @param {Function} fn The function to call
  4484. * @param {Object} scope Optional scope object
  4485. */
  4486. eachItem: function(fn, scope) {
  4487. if(this.items && this.items.each){
  4488. this.items.each(fn, scope || this);
  4489. }
  4490. },
  4491. /**
  4492. * @private
  4493. * Passes the resize call through to the inner panel
  4494. */
  4495. onResize: function(adjWidth, adjHeight, rawWidth, rawHeight) {
  4496. var innerCt = this.innerCt;
  4497. if (this.rendered && innerCt.rendered) {
  4498. innerCt.setSize(adjWidth, adjHeight);
  4499. }
  4500. Ext.form.CompositeField.superclass.onResize.apply(this, arguments);
  4501. },
  4502. /**
  4503. * @private
  4504. * Forces the internal container to be laid out again
  4505. */
  4506. doLayout: function(shallow, force) {
  4507. if (this.rendered) {
  4508. var innerCt = this.innerCt;
  4509. innerCt.forceLayout = this.ownerCt.forceLayout;
  4510. innerCt.doLayout(shallow, force);
  4511. }
  4512. },
  4513. /**
  4514. * @private
  4515. */
  4516. beforeDestroy: function(){
  4517. Ext.destroy(this.innerCt);
  4518. Ext.form.CompositeField.superclass.beforeDestroy.call(this);
  4519. },
  4520. //override the behaviour to check sub items.
  4521. setReadOnly : function(readOnly) {
  4522. if (readOnly == undefined) {
  4523. readOnly = true;
  4524. }
  4525. readOnly = !!readOnly;
  4526. if(this.rendered){
  4527. this.eachItem(function(item){
  4528. item.setReadOnly(readOnly);
  4529. });
  4530. }
  4531. this.readOnly = readOnly;
  4532. },
  4533. onShow : function() {
  4534. Ext.form.CompositeField.superclass.onShow.call(this);
  4535. this.doLayout();
  4536. },
  4537. //override the behaviour to check sub items.
  4538. onDisable : function(){
  4539. this.eachItem(function(item){
  4540. item.disable();
  4541. });
  4542. },
  4543. //override the behaviour to check sub items.
  4544. onEnable : function(){
  4545. this.eachItem(function(item){
  4546. item.enable();
  4547. });
  4548. }
  4549. });
  4550. Ext.reg('compositefield', Ext.form.CompositeField);/**
  4551. * @class Ext.form.Radio
  4552. * @extends Ext.form.Checkbox
  4553. * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
  4554. * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
  4555. * @constructor
  4556. * Creates a new Radio
  4557. * @param {Object} config Configuration options
  4558. * @xtype radio
  4559. */
  4560. Ext.form.Radio = Ext.extend(Ext.form.Checkbox, {
  4561. inputType: 'radio',
  4562. /**
  4563. * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
  4564. * @method
  4565. */
  4566. markInvalid : Ext.emptyFn,
  4567. /**
  4568. * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
  4569. * @method
  4570. */
  4571. clearInvalid : Ext.emptyFn,
  4572. /**
  4573. * If this radio is part of a group, it will return the selected value
  4574. * @return {String}
  4575. */
  4576. getGroupValue : function(){
  4577. var p = this.el.up('form') || Ext.getBody();
  4578. var c = p.child('input[name="'+this.el.dom.name+'"]:checked', true);
  4579. return c ? c.value : null;
  4580. },
  4581. /**
  4582. * Sets either the checked/unchecked status of this Radio, or, if a string value
  4583. * is passed, checks a sibling Radio of the same name whose value is the value specified.
  4584. * @param value {String/Boolean} Checked value, or the value of the sibling radio button to check.
  4585. * @return {Ext.form.Field} this
  4586. */
  4587. setValue : function(v){
  4588. var checkEl,
  4589. els,
  4590. radio;
  4591. if (typeof v == 'boolean') {
  4592. Ext.form.Radio.superclass.setValue.call(this, v);
  4593. } else if (this.rendered) {
  4594. checkEl = this.getCheckEl();
  4595. radio = checkEl.child('input[name="' + this.el.dom.name + '"][value="' + v + '"]', true);
  4596. if(radio){
  4597. Ext.getCmp(radio.id).setValue(true);
  4598. }
  4599. }
  4600. if(this.rendered && this.checked){
  4601. checkEl = checkEl || this.getCheckEl();
  4602. els = this.getCheckEl().select('input[name="' + this.el.dom.name + '"]');
  4603. els.each(function(el){
  4604. if(el.dom.id != this.id){
  4605. Ext.getCmp(el.dom.id).setValue(false);
  4606. }
  4607. }, this);
  4608. }
  4609. return this;
  4610. },
  4611. // private
  4612. getCheckEl: function(){
  4613. if(this.inGroup){
  4614. return this.el.up('.x-form-radio-group');
  4615. }
  4616. return this.el.up('form') || Ext.getBody();
  4617. }
  4618. });
  4619. Ext.reg('radio', Ext.form.Radio);
  4620. /**
  4621. * @class Ext.form.RadioGroup
  4622. * @extends Ext.form.CheckboxGroup
  4623. * A grouping container for {@link Ext.form.Radio} controls.
  4624. * @constructor
  4625. * Creates a new RadioGroup
  4626. * @param {Object} config Configuration options
  4627. * @xtype radiogroup
  4628. */
  4629. Ext.form.RadioGroup = Ext.extend(Ext.form.CheckboxGroup, {
  4630. /**
  4631. * @cfg {Array} items An Array of {@link Ext.form.Radio Radio}s or Radio config objects
  4632. * to arrange in the group.
  4633. */
  4634. /**
  4635. * @cfg {Boolean} allowBlank True to allow every item in the group to be blank (defaults to true).
  4636. * If allowBlank = false and no items are selected at validation time, {@link @blankText} will
  4637. * be used as the error text.
  4638. */
  4639. allowBlank : true,
  4640. /**
  4641. * @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails
  4642. * (defaults to 'You must select one item in this group')
  4643. */
  4644. blankText : 'You must select one item in this group',
  4645. // private
  4646. defaultType : 'radio',
  4647. // private
  4648. groupCls : 'x-form-radio-group',
  4649. /**
  4650. * @event change
  4651. * Fires when the state of a child radio changes.
  4652. * @param {Ext.form.RadioGroup} this
  4653. * @param {Ext.form.Radio} checked The checked radio
  4654. */
  4655. /**
  4656. * Gets the selected {@link Ext.form.Radio} in the group, if it exists.
  4657. * @return {Ext.form.Radio} The selected radio.
  4658. */
  4659. getValue : function(){
  4660. var out = null;
  4661. this.eachItem(function(item){
  4662. if(item.checked){
  4663. out = item;
  4664. return false;
  4665. }
  4666. });
  4667. return out;
  4668. },
  4669. /**
  4670. * Sets the checked radio in the group.
  4671. * @param {String/Ext.form.Radio} id The radio to check.
  4672. * @param {Boolean} value The value to set the radio.
  4673. * @return {Ext.form.RadioGroup} this
  4674. */
  4675. onSetValue : function(id, value){
  4676. if(arguments.length > 1){
  4677. var f = this.getBox(id);
  4678. if(f){
  4679. f.setValue(value);
  4680. if(f.checked){
  4681. this.eachItem(function(item){
  4682. if (item !== f){
  4683. item.setValue(false);
  4684. }
  4685. });
  4686. }
  4687. }
  4688. }else{
  4689. this.setValueForItem(id);
  4690. }
  4691. },
  4692. setValueForItem : function(val){
  4693. val = String(val).split(',')[0];
  4694. this.eachItem(function(item){
  4695. item.setValue(val == item.inputValue);
  4696. });
  4697. },
  4698. // private
  4699. fireChecked : function(){
  4700. if(!this.checkTask){
  4701. this.checkTask = new Ext.util.DelayedTask(this.bufferChecked, this);
  4702. }
  4703. this.checkTask.delay(10);
  4704. },
  4705. // private
  4706. bufferChecked : function(){
  4707. var out = null;
  4708. this.eachItem(function(item){
  4709. if(item.checked){
  4710. out = item;
  4711. return false;
  4712. }
  4713. });
  4714. this.fireEvent('change', this, out);
  4715. },
  4716. onDestroy : function(){
  4717. if(this.checkTask){
  4718. this.checkTask.cancel();
  4719. this.checkTask = null;
  4720. }
  4721. Ext.form.RadioGroup.superclass.onDestroy.call(this);
  4722. }
  4723. });
  4724. Ext.reg('radiogroup', Ext.form.RadioGroup);
  4725. /**
  4726. * @class Ext.form.Hidden
  4727. * @extends Ext.form.Field
  4728. * A basic hidden field for storing hidden values in forms that need to be passed in the form submit.
  4729. * @constructor
  4730. * Create a new Hidden field.
  4731. * @param {Object} config Configuration options
  4732. * @xtype hidden
  4733. */
  4734. Ext.form.Hidden = Ext.extend(Ext.form.Field, {
  4735. // private
  4736. inputType : 'hidden',
  4737. shouldLayout: false,
  4738. // private
  4739. onRender : function(){
  4740. Ext.form.Hidden.superclass.onRender.apply(this, arguments);
  4741. },
  4742. // private
  4743. initEvents : function(){
  4744. this.originalValue = this.getValue();
  4745. },
  4746. // These are all private overrides
  4747. setSize : Ext.emptyFn,
  4748. setWidth : Ext.emptyFn,
  4749. setHeight : Ext.emptyFn,
  4750. setPosition : Ext.emptyFn,
  4751. setPagePosition : Ext.emptyFn,
  4752. markInvalid : Ext.emptyFn,
  4753. clearInvalid : Ext.emptyFn
  4754. });
  4755. Ext.reg('hidden', Ext.form.Hidden);/**
  4756. * @class Ext.form.BasicForm
  4757. * @extends Ext.util.Observable
  4758. * <p>Encapsulates the DOM &lt;form> element at the heart of the {@link Ext.form.FormPanel FormPanel} class, and provides
  4759. * input field management, validation, submission, and form loading services.</p>
  4760. * <p>By default, Ext Forms are submitted through Ajax, using an instance of {@link Ext.form.Action.Submit}.
  4761. * To enable normal browser submission of an Ext Form, use the {@link #standardSubmit} config option.</p>
  4762. * <p><b><u>File Uploads</u></b></p>
  4763. * <p>{@link #fileUpload File uploads} are not performed using Ajax submission, that
  4764. * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard
  4765. * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its
  4766. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  4767. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  4768. * but removed after the return data has been gathered.</p>
  4769. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  4770. * server is using JSON to send the return object, then the
  4771. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  4772. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  4773. * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  4774. * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
  4775. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  4776. * is created containing a <tt>responseText</tt> property in order to conform to the
  4777. * requirements of event handlers and callbacks.</p>
  4778. * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
  4779. * and some server technologies (notably JEE) may require some custom processing in order to
  4780. * retrieve parameter names and parameter values from the packet content.</p>
  4781. * @constructor
  4782. * @param {Mixed} el The form element or its id
  4783. * @param {Object} config Configuration options
  4784. */
  4785. Ext.form.BasicForm = Ext.extend(Ext.util.Observable, {
  4786. constructor: function(el, config){
  4787. Ext.apply(this, config);
  4788. if(Ext.isString(this.paramOrder)){
  4789. this.paramOrder = this.paramOrder.split(/[\s,|]/);
  4790. }
  4791. /**
  4792. * A {@link Ext.util.MixedCollection MixedCollection} containing all the Ext.form.Fields in this form.
  4793. * @type MixedCollection
  4794. * @property items
  4795. */
  4796. this.items = new Ext.util.MixedCollection(false, function(o){
  4797. return o.getItemId();
  4798. });
  4799. this.addEvents(
  4800. /**
  4801. * @event beforeaction
  4802. * Fires before any action is performed. Return false to cancel the action.
  4803. * @param {Form} this
  4804. * @param {Action} action The {@link Ext.form.Action} to be performed
  4805. */
  4806. 'beforeaction',
  4807. /**
  4808. * @event actionfailed
  4809. * Fires when an action fails.
  4810. * @param {Form} this
  4811. * @param {Action} action The {@link Ext.form.Action} that failed
  4812. */
  4813. 'actionfailed',
  4814. /**
  4815. * @event actioncomplete
  4816. * Fires when an action is completed.
  4817. * @param {Form} this
  4818. * @param {Action} action The {@link Ext.form.Action} that completed
  4819. */
  4820. 'actioncomplete'
  4821. );
  4822. if(el){
  4823. this.initEl(el);
  4824. }
  4825. Ext.form.BasicForm.superclass.constructor.call(this);
  4826. },
  4827. /**
  4828. * @cfg {String} method
  4829. * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
  4830. */
  4831. /**
  4832. * @cfg {DataReader} reader
  4833. * An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read
  4834. * data when executing 'load' actions. This is optional as there is built-in
  4835. * support for processing JSON. For additional information on using an XMLReader
  4836. * see the example provided in examples/form/xml-form.html.
  4837. */
  4838. /**
  4839. * @cfg {DataReader} errorReader
  4840. * <p>An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to
  4841. * read field error messages returned from 'submit' actions. This is optional
  4842. * as there is built-in support for processing JSON.</p>
  4843. * <p>The Records which provide messages for the invalid Fields must use the
  4844. * Field name (or id) as the Record ID, and must contain a field called 'msg'
  4845. * which contains the error message.</p>
  4846. * <p>The errorReader does not have to be a full-blown implementation of a
  4847. * DataReader. It simply needs to implement a <tt>read(xhr)</tt> function
  4848. * which returns an Array of Records in an object with the following
  4849. * structure:</p><pre><code>
  4850. {
  4851. records: recordArray
  4852. }
  4853. </code></pre>
  4854. */
  4855. /**
  4856. * @cfg {String} url
  4857. * The URL to use for form actions if one isn't supplied in the
  4858. * <code>{@link #doAction doAction} options</code>.
  4859. */
  4860. /**
  4861. * @cfg {Boolean} fileUpload
  4862. * Set to true if this form is a file upload.
  4863. * <p>File uploads are not performed using normal 'Ajax' techniques, that is they are <b>not</b>
  4864. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  4865. * DOM <tt>&lt;form></tt> element temporarily modified to have its
  4866. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  4867. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  4868. * but removed after the return data has been gathered.</p>
  4869. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  4870. * server is using JSON to send the return object, then the
  4871. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  4872. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  4873. * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  4874. * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
  4875. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  4876. * is created containing a <tt>responseText</tt> property in order to conform to the
  4877. * requirements of event handlers and callbacks.</p>
  4878. * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
  4879. * and some server technologies (notably JEE) may require some custom processing in order to
  4880. * retrieve parameter names and parameter values from the packet content.</p>
  4881. */
  4882. /**
  4883. * @cfg {Object} baseParams
  4884. * <p>Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.</p>
  4885. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
  4886. */
  4887. /**
  4888. * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
  4889. */
  4890. timeout: 30,
  4891. /**
  4892. * @cfg {Object} api (Optional) If specified load and submit actions will be handled
  4893. * with {@link Ext.form.Action.DirectLoad} and {@link Ext.form.Action.DirectSubmit}.
  4894. * Methods which have been imported by Ext.Direct can be specified here to load and submit
  4895. * forms.
  4896. * Such as the following:<pre><code>
  4897. api: {
  4898. load: App.ss.MyProfile.load,
  4899. submit: App.ss.MyProfile.submit
  4900. }
  4901. </code></pre>
  4902. * <p>Load actions can use <code>{@link #paramOrder}</code> or <code>{@link #paramsAsHash}</code>
  4903. * to customize how the load method is invoked.
  4904. * Submit actions will always use a standard form submit. The formHandler configuration must
  4905. * be set on the associated server-side method which has been imported by Ext.Direct</p>
  4906. */
  4907. /**
  4908. * @cfg {Array/String} paramOrder <p>A list of params to be executed server side.
  4909. * Defaults to <tt>undefined</tt>. Only used for the <code>{@link #api}</code>
  4910. * <code>load</code> configuration.</p>
  4911. * <br><p>Specify the params in the order in which they must be executed on the
  4912. * server-side as either (1) an Array of String values, or (2) a String of params
  4913. * delimited by either whitespace, comma, or pipe. For example,
  4914. * any of the following would be acceptable:</p><pre><code>
  4915. paramOrder: ['param1','param2','param3']
  4916. paramOrder: 'param1 param2 param3'
  4917. paramOrder: 'param1,param2,param3'
  4918. paramOrder: 'param1|param2|param'
  4919. </code></pre>
  4920. */
  4921. paramOrder: undefined,
  4922. /**
  4923. * @cfg {Boolean} paramsAsHash Only used for the <code>{@link #api}</code>
  4924. * <code>load</code> configuration. Send parameters as a collection of named
  4925. * arguments (defaults to <tt>false</tt>). Providing a
  4926. * <tt>{@link #paramOrder}</tt> nullifies this configuration.
  4927. */
  4928. paramsAsHash: false,
  4929. /**
  4930. * @cfg {String} waitTitle
  4931. * The default title to show for the waiting message box (defaults to <tt>'Please Wait...'</tt>)
  4932. */
  4933. waitTitle: 'Please Wait...',
  4934. // private
  4935. activeAction : null,
  4936. /**
  4937. * @cfg {Boolean} trackResetOnLoad If set to <tt>true</tt>, {@link #reset}() resets to the last loaded
  4938. * or {@link #setValues}() data instead of when the form was first created. Defaults to <tt>false</tt>.
  4939. */
  4940. trackResetOnLoad : false,
  4941. /**
  4942. * @cfg {Boolean} standardSubmit
  4943. * <p>If set to <tt>true</tt>, standard HTML form submits are used instead
  4944. * of XHR (Ajax) style form submissions. Defaults to <tt>false</tt>.</p>
  4945. * <br><p><b>Note:</b> When using <code>standardSubmit</code>, the
  4946. * <code>options</code> to <code>{@link #submit}</code> are ignored because
  4947. * Ext's Ajax infrastracture is bypassed. To pass extra parameters (e.g.
  4948. * <code>baseParams</code> and <code>params</code>), utilize hidden fields
  4949. * to submit extra data, for example:</p>
  4950. * <pre><code>
  4951. new Ext.FormPanel({
  4952. standardSubmit: true,
  4953. baseParams: {
  4954. foo: 'bar'
  4955. },
  4956. {@link url}: 'myProcess.php',
  4957. items: [{
  4958. xtype: 'textfield',
  4959. name: 'userName'
  4960. }],
  4961. buttons: [{
  4962. text: 'Save',
  4963. handler: function(){
  4964. var fp = this.ownerCt.ownerCt,
  4965. form = fp.getForm();
  4966. if (form.isValid()) {
  4967. // check if there are baseParams and if
  4968. // hiddent items have been added already
  4969. if (fp.baseParams && !fp.paramsAdded) {
  4970. // add hidden items for all baseParams
  4971. for (i in fp.baseParams) {
  4972. fp.add({
  4973. xtype: 'hidden',
  4974. name: i,
  4975. value: fp.baseParams[i]
  4976. });
  4977. }
  4978. fp.doLayout();
  4979. // set a custom flag to prevent re-adding
  4980. fp.paramsAdded = true;
  4981. }
  4982. form.{@link #submit}();
  4983. }
  4984. }
  4985. }]
  4986. });
  4987. * </code></pre>
  4988. */
  4989. /**
  4990. * By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific
  4991. * element by passing it or its id or mask the form itself by passing in true.
  4992. * @type Mixed
  4993. * @property waitMsgTarget
  4994. */
  4995. // private
  4996. initEl : function(el){
  4997. this.el = Ext.get(el);
  4998. this.id = this.el.id || Ext.id();
  4999. if(!this.standardSubmit){
  5000. this.el.on('submit', this.onSubmit, this);
  5001. }
  5002. this.el.addClass('x-form');
  5003. },
  5004. /**
  5005. * Get the HTML form Element
  5006. * @return Ext.Element
  5007. */
  5008. getEl: function(){
  5009. return this.el;
  5010. },
  5011. // private
  5012. onSubmit : function(e){
  5013. e.stopEvent();
  5014. },
  5015. /**
  5016. * Destroys this object.
  5017. * @private
  5018. * @param {Boolean} bound true if the object is bound to a form panel. If this is the case
  5019. * the FormPanel will take care of destroying certain things, so we're just doubling up.
  5020. */
  5021. destroy: function(bound){
  5022. if(bound !== true){
  5023. this.items.each(function(f){
  5024. Ext.destroy(f);
  5025. });
  5026. Ext.destroy(this.el);
  5027. }
  5028. this.items.clear();
  5029. this.purgeListeners();
  5030. },
  5031. /**
  5032. * Returns true if client-side validation on the form is successful.
  5033. * @return Boolean
  5034. */
  5035. isValid : function(){
  5036. var valid = true;
  5037. this.items.each(function(f){
  5038. if(!f.validate()){
  5039. valid = false;
  5040. }
  5041. });
  5042. return valid;
  5043. },
  5044. /**
  5045. * <p>Returns true if any fields in this form have changed from their original values.</p>
  5046. * <p>Note that if this BasicForm was configured with {@link #trackResetOnLoad} then the
  5047. * Fields' <i>original values</i> are updated when the values are loaded by {@link #setValues}
  5048. * or {@link #loadRecord}.</p>
  5049. * @return Boolean
  5050. */
  5051. isDirty : function(){
  5052. var dirty = false;
  5053. this.items.each(function(f){
  5054. if(f.isDirty()){
  5055. dirty = true;
  5056. return false;
  5057. }
  5058. });
  5059. return dirty;
  5060. },
  5061. /**
  5062. * Performs a predefined action ({@link Ext.form.Action.Submit} or
  5063. * {@link Ext.form.Action.Load}) or a custom extension of {@link Ext.form.Action}
  5064. * to perform application-specific processing.
  5065. * @param {String/Object} actionName The name of the predefined action type,
  5066. * or instance of {@link Ext.form.Action} to perform.
  5067. * @param {Object} options (optional) The options to pass to the {@link Ext.form.Action}.
  5068. * All of the config options listed below are supported by both the
  5069. * {@link Ext.form.Action.Submit submit} and {@link Ext.form.Action.Load load}
  5070. * actions unless otherwise noted (custom actions could also accept
  5071. * other config options):<ul>
  5072. *
  5073. * <li><b>url</b> : String<div class="sub-desc">The url for the action (defaults
  5074. * to the form's {@link #url}.)</div></li>
  5075. *
  5076. * <li><b>method</b> : String<div class="sub-desc">The form method to use (defaults
  5077. * to the form's method, or POST if not defined)</div></li>
  5078. *
  5079. * <li><b>params</b> : String/Object<div class="sub-desc"><p>The params to pass
  5080. * (defaults to the form's baseParams, or none if not defined)</p>
  5081. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
  5082. *
  5083. * <li><b>headers</b> : Object<div class="sub-desc">Request headers to set for the action
  5084. * (defaults to the form's default headers)</div></li>
  5085. *
  5086. * <li><b>success</b> : Function<div class="sub-desc">The callback that will
  5087. * be invoked after a successful response (see top of
  5088. * {@link Ext.form.Action.Submit submit} and {@link Ext.form.Action.Load load}
  5089. * for a description of what constitutes a successful response).
  5090. * The function is passed the following parameters:<ul>
  5091. * <li><tt>form</tt> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
  5092. * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.
  5093. * <div class="sub-desc">The action object contains these properties of interest:<ul>
  5094. * <li><tt>{@link Ext.form.Action#response response}</tt></li>
  5095. * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>
  5096. * <li><tt>{@link Ext.form.Action#type type}</tt></li>
  5097. * </ul></div></li></ul></div></li>
  5098. *
  5099. * <li><b>failure</b> : Function<div class="sub-desc">The callback that will be invoked after a
  5100. * failed transaction attempt. The function is passed the following parameters:<ul>
  5101. * <li><tt>form</tt> : The {@link Ext.form.BasicForm} that requested the action.</li>
  5102. * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.
  5103. * <div class="sub-desc">The action object contains these properties of interest:<ul>
  5104. * <li><tt>{@link Ext.form.Action#failureType failureType}</tt></li>
  5105. * <li><tt>{@link Ext.form.Action#response response}</tt></li>
  5106. * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>
  5107. * <li><tt>{@link Ext.form.Action#type type}</tt></li>
  5108. * </ul></div></li></ul></div></li>
  5109. *
  5110. * <li><b>scope</b> : Object<div class="sub-desc">The scope in which to call the
  5111. * callback functions (The <tt>this</tt> reference for the callback functions).</div></li>
  5112. *
  5113. * <li><b>clientValidation</b> : Boolean<div class="sub-desc">Submit Action only.
  5114. * Determines whether a Form's fields are validated in a final call to
  5115. * {@link Ext.form.BasicForm#isValid isValid} prior to submission. Set to <tt>false</tt>
  5116. * to prevent this. If undefined, pre-submission field validation is performed.</div></li></ul>
  5117. *
  5118. * @return {BasicForm} this
  5119. */
  5120. doAction : function(action, options){
  5121. if(Ext.isString(action)){
  5122. action = new Ext.form.Action.ACTION_TYPES[action](this, options);
  5123. }
  5124. if(this.fireEvent('beforeaction', this, action) !== false){
  5125. this.beforeAction(action);
  5126. action.run.defer(100, action);
  5127. }
  5128. return this;
  5129. },
  5130. /**
  5131. * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Submit submit action}.
  5132. * @param {Object} options The options to pass to the action (see {@link #doAction} for details).<br>
  5133. * <p><b>Note:</b> this is ignored when using the {@link #standardSubmit} option.</p>
  5134. * <p>The following code:</p><pre><code>
  5135. myFormPanel.getForm().submit({
  5136. clientValidation: true,
  5137. url: 'updateConsignment.php',
  5138. params: {
  5139. newStatus: 'delivered'
  5140. },
  5141. success: function(form, action) {
  5142. Ext.Msg.alert('Success', action.result.msg);
  5143. },
  5144. failure: function(form, action) {
  5145. switch (action.failureType) {
  5146. case Ext.form.Action.CLIENT_INVALID:
  5147. Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
  5148. break;
  5149. case Ext.form.Action.CONNECT_FAILURE:
  5150. Ext.Msg.alert('Failure', 'Ajax communication failed');
  5151. break;
  5152. case Ext.form.Action.SERVER_INVALID:
  5153. Ext.Msg.alert('Failure', action.result.msg);
  5154. }
  5155. }
  5156. });
  5157. </code></pre>
  5158. * would process the following server response for a successful submission:<pre><code>
  5159. {
  5160. "success":true, // note this is Boolean, not string
  5161. "msg":"Consignment updated"
  5162. }
  5163. </code></pre>
  5164. * and the following server response for a failed submission:<pre><code>
  5165. {
  5166. "success":false, // note this is Boolean, not string
  5167. "msg":"You do not have permission to perform this operation"
  5168. }
  5169. </code></pre>
  5170. * @return {BasicForm} this
  5171. */
  5172. submit : function(options){
  5173. options = options || {};
  5174. if(this.standardSubmit){
  5175. var v = options.clientValidation === false || this.isValid();
  5176. if(v){
  5177. var el = this.el.dom;
  5178. if(this.url && Ext.isEmpty(el.action)){
  5179. el.action = this.url;
  5180. }
  5181. el.submit();
  5182. }
  5183. return v;
  5184. }
  5185. var submitAction = String.format('{0}submit', this.api ? 'direct' : '');
  5186. this.doAction(submitAction, options);
  5187. return this;
  5188. },
  5189. /**
  5190. * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Load load action}.
  5191. * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
  5192. * @return {BasicForm} this
  5193. */
  5194. load : function(options){
  5195. var loadAction = String.format('{0}load', this.api ? 'direct' : '');
  5196. this.doAction(loadAction, options);
  5197. return this;
  5198. },
  5199. /**
  5200. * Persists the values in this form into the passed {@link Ext.data.Record} object in a beginEdit/endEdit block.
  5201. * @param {Record} record The record to edit
  5202. * @return {BasicForm} this
  5203. */
  5204. updateRecord : function(record){
  5205. record.beginEdit();
  5206. var fs = record.fields,
  5207. field,
  5208. value;
  5209. fs.each(function(f){
  5210. field = this.findField(f.name);
  5211. if(field){
  5212. value = field.getValue();
  5213. if (Ext.type(value) !== false && value.getGroupValue) {
  5214. value = value.getGroupValue();
  5215. } else if ( field.eachItem ) {
  5216. value = [];
  5217. field.eachItem(function(item){
  5218. value.push(item.getValue());
  5219. });
  5220. }
  5221. record.set(f.name, value);
  5222. }
  5223. }, this);
  5224. record.endEdit();
  5225. return this;
  5226. },
  5227. /**
  5228. * Loads an {@link Ext.data.Record} into this form by calling {@link #setValues} with the
  5229. * {@link Ext.data.Record#data record data}.
  5230. * See also {@link #trackResetOnLoad}.
  5231. * @param {Record} record The record to load
  5232. * @return {BasicForm} this
  5233. */
  5234. loadRecord : function(record){
  5235. this.setValues(record.data);
  5236. return this;
  5237. },
  5238. // private
  5239. beforeAction : function(action){
  5240. // Call HtmlEditor's syncValue before actions
  5241. this.items.each(function(f){
  5242. if(f.isFormField && f.syncValue){
  5243. f.syncValue();
  5244. }
  5245. });
  5246. var o = action.options;
  5247. if(o.waitMsg){
  5248. if(this.waitMsgTarget === true){
  5249. this.el.mask(o.waitMsg, 'x-mask-loading');
  5250. }else if(this.waitMsgTarget){
  5251. this.waitMsgTarget = Ext.get(this.waitMsgTarget);
  5252. this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
  5253. }else{
  5254. Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle);
  5255. }
  5256. }
  5257. },
  5258. // private
  5259. afterAction : function(action, success){
  5260. this.activeAction = null;
  5261. var o = action.options;
  5262. if(o.waitMsg){
  5263. if(this.waitMsgTarget === true){
  5264. this.el.unmask();
  5265. }else if(this.waitMsgTarget){
  5266. this.waitMsgTarget.unmask();
  5267. }else{
  5268. Ext.MessageBox.updateProgress(1);
  5269. Ext.MessageBox.hide();
  5270. }
  5271. }
  5272. if(success){
  5273. if(o.reset){
  5274. this.reset();
  5275. }
  5276. Ext.callback(o.success, o.scope, [this, action]);
  5277. this.fireEvent('actioncomplete', this, action);
  5278. }else{
  5279. Ext.callback(o.failure, o.scope, [this, action]);
  5280. this.fireEvent('actionfailed', this, action);
  5281. }
  5282. },
  5283. /**
  5284. * Find a {@link Ext.form.Field} in this form.
  5285. * @param {String} id The value to search for (specify either a {@link Ext.Component#id id},
  5286. * {@link Ext.grid.Column#dataIndex dataIndex}, {@link Ext.form.Field#getName name or hiddenName}).
  5287. * @return Field
  5288. */
  5289. findField : function(id) {
  5290. var field = this.items.get(id);
  5291. if (!Ext.isObject(field)) {
  5292. //searches for the field corresponding to the given id. Used recursively for composite fields
  5293. var findMatchingField = function(f) {
  5294. if (f.isFormField) {
  5295. if (f.dataIndex == id || f.id == id || f.getName() == id) {
  5296. field = f;
  5297. return false;
  5298. } else if (f.isComposite) {
  5299. return f.items.each(findMatchingField);
  5300. } else if (f instanceof Ext.form.CheckboxGroup && f.rendered) {
  5301. return f.eachItem(findMatchingField);
  5302. }
  5303. }
  5304. };
  5305. this.items.each(findMatchingField);
  5306. }
  5307. return field || null;
  5308. },
  5309. /**
  5310. * Mark fields in this form invalid in bulk.
  5311. * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
  5312. * @return {BasicForm} this
  5313. */
  5314. markInvalid : function(errors){
  5315. if (Ext.isArray(errors)) {
  5316. for(var i = 0, len = errors.length; i < len; i++){
  5317. var fieldError = errors[i];
  5318. var f = this.findField(fieldError.id);
  5319. if(f){
  5320. f.markInvalid(fieldError.msg);
  5321. }
  5322. }
  5323. } else {
  5324. var field, id;
  5325. for(id in errors){
  5326. if(!Ext.isFunction(errors[id]) && (field = this.findField(id))){
  5327. field.markInvalid(errors[id]);
  5328. }
  5329. }
  5330. }
  5331. return this;
  5332. },
  5333. /**
  5334. * Set values for fields in this form in bulk.
  5335. * @param {Array/Object} values Either an array in the form:<pre><code>
  5336. [{id:'clientName', value:'Fred. Olsen Lines'},
  5337. {id:'portOfLoading', value:'FXT'},
  5338. {id:'portOfDischarge', value:'OSL'} ]</code></pre>
  5339. * or an object hash of the form:<pre><code>
  5340. {
  5341. clientName: 'Fred. Olsen Lines',
  5342. portOfLoading: 'FXT',
  5343. portOfDischarge: 'OSL'
  5344. }</code></pre>
  5345. * @return {BasicForm} this
  5346. */
  5347. setValues : function(values){
  5348. if(Ext.isArray(values)){ // array of objects
  5349. for(var i = 0, len = values.length; i < len; i++){
  5350. var v = values[i];
  5351. var f = this.findField(v.id);
  5352. if(f){
  5353. f.setValue(v.value);
  5354. if(this.trackResetOnLoad){
  5355. f.originalValue = f.getValue();
  5356. }
  5357. }
  5358. }
  5359. }else{ // object hash
  5360. var field, id;
  5361. for(id in values){
  5362. if(!Ext.isFunction(values[id]) && (field = this.findField(id))){
  5363. field.setValue(values[id]);
  5364. if(this.trackResetOnLoad){
  5365. field.originalValue = field.getValue();
  5366. }
  5367. }
  5368. }
  5369. }
  5370. return this;
  5371. },
  5372. /**
  5373. * <p>Returns the fields in this form as an object with key/value pairs as they would be submitted using a standard form submit.
  5374. * If multiple fields exist with the same name they are returned as an array.</p>
  5375. * <p><b>Note:</b> The values are collected from all enabled HTML input elements within the form, <u>not</u> from
  5376. * the Ext Field objects. This means that all returned values are Strings (or Arrays of Strings) and that the
  5377. * value can potentially be the emptyText of a field.</p>
  5378. * @param {Boolean} asString (optional) Pass true to return the values as a string. (defaults to false, returning an Object)
  5379. * @return {String/Object}
  5380. */
  5381. getValues : function(asString){
  5382. var fs = Ext.lib.Ajax.serializeForm(this.el.dom);
  5383. if(asString === true){
  5384. return fs;
  5385. }
  5386. return Ext.urlDecode(fs);
  5387. },
  5388. /**
  5389. * Retrieves the fields in the form as a set of key/value pairs, using the {@link Ext.form.Field#getValue getValue()} method.
  5390. * If multiple fields exist with the same name they are returned as an array.
  5391. * @param {Boolean} dirtyOnly (optional) True to return only fields that are dirty.
  5392. * @return {Object} The values in the form
  5393. */
  5394. getFieldValues : function(dirtyOnly){
  5395. var o = {},
  5396. n,
  5397. key,
  5398. val;
  5399. this.items.each(function(f) {
  5400. if (!f.disabled && (dirtyOnly !== true || f.isDirty())) {
  5401. n = f.getName();
  5402. key = o[n];
  5403. val = f.getValue();
  5404. if(Ext.isDefined(key)){
  5405. if(Ext.isArray(key)){
  5406. o[n].push(val);
  5407. }else{
  5408. o[n] = [key, val];
  5409. }
  5410. }else{
  5411. o[n] = val;
  5412. }
  5413. }
  5414. });
  5415. return o;
  5416. },
  5417. /**
  5418. * Clears all invalid messages in this form.
  5419. * @return {BasicForm} this
  5420. */
  5421. clearInvalid : function(){
  5422. this.items.each(function(f){
  5423. f.clearInvalid();
  5424. });
  5425. return this;
  5426. },
  5427. /**
  5428. * Resets this form.
  5429. * @return {BasicForm} this
  5430. */
  5431. reset : function(){
  5432. this.items.each(function(f){
  5433. f.reset();
  5434. });
  5435. return this;
  5436. },
  5437. /**
  5438. * Add Ext.form Components to this form's Collection. This does not result in rendering of
  5439. * the passed Component, it just enables the form to validate Fields, and distribute values to
  5440. * Fields.
  5441. * <p><b>You will not usually call this function. In order to be rendered, a Field must be added
  5442. * to a {@link Ext.Container Container}, usually an {@link Ext.form.FormPanel FormPanel}.
  5443. * The FormPanel to which the field is added takes care of adding the Field to the BasicForm's
  5444. * collection.</b></p>
  5445. * @param {Field} field1
  5446. * @param {Field} field2 (optional)
  5447. * @param {Field} etc (optional)
  5448. * @return {BasicForm} this
  5449. */
  5450. add : function(){
  5451. this.items.addAll(Array.prototype.slice.call(arguments, 0));
  5452. return this;
  5453. },
  5454. /**
  5455. * Removes a field from the items collection (does NOT remove its markup).
  5456. * @param {Field} field
  5457. * @return {BasicForm} this
  5458. */
  5459. remove : function(field){
  5460. this.items.remove(field);
  5461. return this;
  5462. },
  5463. /**
  5464. * Removes all fields from the collection that have been destroyed.
  5465. */
  5466. cleanDestroyed : function() {
  5467. this.items.filterBy(function(o) { return !!o.isDestroyed; }).each(this.remove, this);
  5468. },
  5469. /**
  5470. * Iterates through the {@link Ext.form.Field Field}s which have been {@link #add add}ed to this BasicForm,
  5471. * checks them for an id attribute, and calls {@link Ext.form.Field#applyToMarkup} on the existing dom element with that id.
  5472. * @return {BasicForm} this
  5473. */
  5474. render : function(){
  5475. this.items.each(function(f){
  5476. if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
  5477. f.applyToMarkup(f.id);
  5478. }
  5479. });
  5480. return this;
  5481. },
  5482. /**
  5483. * Calls {@link Ext#apply} for all fields in this form with the passed object.
  5484. * @param {Object} values
  5485. * @return {BasicForm} this
  5486. */
  5487. applyToFields : function(o){
  5488. this.items.each(function(f){
  5489. Ext.apply(f, o);
  5490. });
  5491. return this;
  5492. },
  5493. /**
  5494. * Calls {@link Ext#applyIf} for all field in this form with the passed object.
  5495. * @param {Object} values
  5496. * @return {BasicForm} this
  5497. */
  5498. applyIfToFields : function(o){
  5499. this.items.each(function(f){
  5500. Ext.applyIf(f, o);
  5501. });
  5502. return this;
  5503. },
  5504. callFieldMethod : function(fnName, args){
  5505. args = args || [];
  5506. this.items.each(function(f){
  5507. if(Ext.isFunction(f[fnName])){
  5508. f[fnName].apply(f, args);
  5509. }
  5510. });
  5511. return this;
  5512. }
  5513. });
  5514. // back compat
  5515. Ext.BasicForm = Ext.form.BasicForm;
  5516. /**
  5517. * @class Ext.form.FormPanel
  5518. * @extends Ext.Panel
  5519. * <p>Standard form container.</p>
  5520. *
  5521. * <p><b><u>Layout</u></b></p>
  5522. * <p>By default, FormPanel is configured with <tt>layout:'form'</tt> to use an {@link Ext.layout.FormLayout}
  5523. * layout manager, which styles and renders fields and labels correctly. When nesting additional Containers
  5524. * within a FormPanel, you should ensure that any descendant Containers which host input Fields use the
  5525. * {@link Ext.layout.FormLayout} layout manager.</p>
  5526. *
  5527. * <p><b><u>BasicForm</u></b></p>
  5528. * <p>Although <b>not listed</b> as configuration options of FormPanel, the FormPanel class accepts all
  5529. * of the config options required to configure its internal {@link Ext.form.BasicForm} for:
  5530. * <div class="mdetail-params"><ul>
  5531. * <li>{@link Ext.form.BasicForm#fileUpload file uploads}</li>
  5532. * <li>functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form</li>
  5533. * </ul></div>
  5534. *
  5535. * <p><b>Note</b>: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
  5536. * the <tt><b>initialConfig</b></tt> property of the FormPanel. Applying {@link Ext.form.BasicForm BasicForm}
  5537. * configuration settings to <b><tt>this</tt></b> will <b>not</b> affect the BasicForm's configuration.</p>
  5538. *
  5539. * <p><b><u>Form Validation</u></b></p>
  5540. * <p>For information on form validation see the following:</p>
  5541. * <div class="mdetail-params"><ul>
  5542. * <li>{@link Ext.form.TextField}</li>
  5543. * <li>{@link Ext.form.VTypes}</li>
  5544. * <li>{@link Ext.form.BasicForm#doAction BasicForm.doAction <b>clientValidation</b> notes}</li>
  5545. * <li><tt>{@link Ext.form.FormPanel#monitorValid monitorValid}</tt></li>
  5546. * </ul></div>
  5547. *
  5548. * <p><b><u>Form Submission</u></b></p>
  5549. * <p>By default, Ext Forms are submitted through Ajax, using {@link Ext.form.Action}. To enable normal browser
  5550. * submission of the {@link Ext.form.BasicForm BasicForm} contained in this FormPanel, see the
  5551. * <tt><b>{@link Ext.form.BasicForm#standardSubmit standardSubmit}</b></tt> option.</p>
  5552. *
  5553. * @constructor
  5554. * @param {Object} config Configuration options
  5555. * @xtype form
  5556. */
  5557. Ext.FormPanel = Ext.extend(Ext.Panel, {
  5558. /**
  5559. * @cfg {String} formId (optional) The id of the FORM tag (defaults to an auto-generated id).
  5560. */
  5561. /**
  5562. * @cfg {Boolean} hideLabels
  5563. * <p><tt>true</tt> to hide field labels by default (sets <tt>display:none</tt>). Defaults to
  5564. * <tt>false</tt>.</p>
  5565. * <p>Also see {@link Ext.Component}.<tt>{@link Ext.Component#hideLabel hideLabel}</tt>.
  5566. */
  5567. /**
  5568. * @cfg {Number} labelPad
  5569. * The default padding in pixels for field labels (defaults to <tt>5</tt>). <tt>labelPad</tt> only
  5570. * applies if <tt>{@link #labelWidth}</tt> is also specified, otherwise it will be ignored.
  5571. */
  5572. /**
  5573. * @cfg {String} labelSeparator
  5574. * See {@link Ext.Component}.<tt>{@link Ext.Component#labelSeparator labelSeparator}</tt>
  5575. */
  5576. /**
  5577. * @cfg {Number} labelWidth The width of labels in pixels. This property cascades to child containers
  5578. * and can be overridden on any child container (e.g., a fieldset can specify a different <tt>labelWidth</tt>
  5579. * for its fields) (defaults to <tt>100</tt>).
  5580. */
  5581. /**
  5582. * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
  5583. */
  5584. /**
  5585. * @cfg {Array} buttons
  5586. * An array of {@link Ext.Button}s or {@link Ext.Button} configs used to add buttons to the footer of this FormPanel.<br>
  5587. * <p>Buttons in the footer of a FormPanel may be configured with the option <tt>formBind: true</tt>. This causes
  5588. * the form's {@link #monitorValid valid state monitor task} to enable/disable those Buttons depending on
  5589. * the form's valid/invalid state.</p>
  5590. */
  5591. /**
  5592. * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to <tt>75</tt>).
  5593. */
  5594. minButtonWidth : 75,
  5595. /**
  5596. * @cfg {String} labelAlign The label alignment value used for the <tt>text-align</tt> specification
  5597. * for the <b>container</b>. Valid values are <tt>"left</tt>", <tt>"top"</tt> or <tt>"right"</tt>
  5598. * (defaults to <tt>"left"</tt>). This property cascades to child <b>containers</b> and can be
  5599. * overridden on any child <b>container</b> (e.g., a fieldset can specify a different <tt>labelAlign</tt>
  5600. * for its fields).
  5601. */
  5602. labelAlign : 'left',
  5603. /**
  5604. * @cfg {Boolean} monitorValid If <tt>true</tt>, the form monitors its valid state <b>client-side</b> and
  5605. * regularly fires the {@link #clientvalidation} event passing that state.<br>
  5606. * <p>When monitoring valid state, the FormPanel enables/disables any of its configured
  5607. * {@link #buttons} which have been configured with <code>formBind: true</code> depending
  5608. * on whether the {@link Ext.form.BasicForm#isValid form is valid} or not. Defaults to <tt>false</tt></p>
  5609. */
  5610. monitorValid : false,
  5611. /**
  5612. * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
  5613. */
  5614. monitorPoll : 200,
  5615. /**
  5616. * @cfg {String} layout Defaults to <tt>'form'</tt>. Normally this configuration property should not be altered.
  5617. * For additional details see {@link Ext.layout.FormLayout} and {@link Ext.Container#layout Ext.Container.layout}.
  5618. */
  5619. layout : 'form',
  5620. // private
  5621. initComponent : function(){
  5622. this.form = this.createForm();
  5623. Ext.FormPanel.superclass.initComponent.call(this);
  5624. this.bodyCfg = {
  5625. tag: 'form',
  5626. cls: this.baseCls + '-body',
  5627. method : this.method || 'POST',
  5628. id : this.formId || Ext.id()
  5629. };
  5630. if(this.fileUpload) {
  5631. this.bodyCfg.enctype = 'multipart/form-data';
  5632. }
  5633. this.initItems();
  5634. this.addEvents(
  5635. /**
  5636. * @event clientvalidation
  5637. * If the monitorValid config option is true, this event fires repetitively to notify of valid state
  5638. * @param {Ext.form.FormPanel} this
  5639. * @param {Boolean} valid true if the form has passed client-side validation
  5640. */
  5641. 'clientvalidation'
  5642. );
  5643. this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']);
  5644. },
  5645. // private
  5646. createForm : function(){
  5647. var config = Ext.applyIf({listeners: {}}, this.initialConfig);
  5648. return new Ext.form.BasicForm(null, config);
  5649. },
  5650. // private
  5651. initFields : function(){
  5652. var f = this.form;
  5653. var formPanel = this;
  5654. var fn = function(c){
  5655. if(formPanel.isField(c)){
  5656. f.add(c);
  5657. }else if(c.findBy && c != formPanel){
  5658. formPanel.applySettings(c);
  5659. //each check required for check/radio groups.
  5660. if(c.items && c.items.each){
  5661. c.items.each(fn, this);
  5662. }
  5663. }
  5664. };
  5665. this.items.each(fn, this);
  5666. },
  5667. // private
  5668. applySettings: function(c){
  5669. var ct = c.ownerCt;
  5670. Ext.applyIf(c, {
  5671. labelAlign: ct.labelAlign,
  5672. labelWidth: ct.labelWidth,
  5673. itemCls: ct.itemCls
  5674. });
  5675. },
  5676. // private
  5677. getLayoutTarget : function(){
  5678. return this.form.el;
  5679. },
  5680. /**
  5681. * Provides access to the {@link Ext.form.BasicForm Form} which this Panel contains.
  5682. * @return {Ext.form.BasicForm} The {@link Ext.form.BasicForm Form} which this Panel contains.
  5683. */
  5684. getForm : function(){
  5685. return this.form;
  5686. },
  5687. // private
  5688. onRender : function(ct, position){
  5689. this.initFields();
  5690. Ext.FormPanel.superclass.onRender.call(this, ct, position);
  5691. this.form.initEl(this.body);
  5692. },
  5693. // private
  5694. beforeDestroy : function(){
  5695. this.stopMonitoring();
  5696. this.form.destroy(true);
  5697. Ext.FormPanel.superclass.beforeDestroy.call(this);
  5698. },
  5699. // Determine if a Component is usable as a form Field.
  5700. isField : function(c) {
  5701. return !!c.setValue && !!c.getValue && !!c.markInvalid && !!c.clearInvalid;
  5702. },
  5703. // private
  5704. initEvents : function(){
  5705. Ext.FormPanel.superclass.initEvents.call(this);
  5706. // Listeners are required here to catch bubbling events from children.
  5707. this.on({
  5708. scope: this,
  5709. add: this.onAddEvent,
  5710. remove: this.onRemoveEvent
  5711. });
  5712. if(this.monitorValid){ // initialize after render
  5713. this.startMonitoring();
  5714. }
  5715. },
  5716. // private
  5717. onAdd: function(c){
  5718. Ext.FormPanel.superclass.onAdd.call(this, c);
  5719. this.processAdd(c);
  5720. },
  5721. // private
  5722. onAddEvent: function(ct, c){
  5723. if(ct !== this){
  5724. this.processAdd(c);
  5725. }
  5726. },
  5727. // private
  5728. processAdd : function(c){
  5729. // If a single form Field, add it
  5730. if(this.isField(c)){
  5731. this.form.add(c);
  5732. // If a Container, add any Fields it might contain
  5733. }else if(c.findBy){
  5734. this.applySettings(c);
  5735. this.form.add.apply(this.form, c.findBy(this.isField));
  5736. }
  5737. },
  5738. // private
  5739. onRemove: function(c){
  5740. Ext.FormPanel.superclass.onRemove.call(this, c);
  5741. this.processRemove(c);
  5742. },
  5743. onRemoveEvent: function(ct, c){
  5744. if(ct !== this){
  5745. this.processRemove(c);
  5746. }
  5747. },
  5748. // private
  5749. processRemove: function(c){
  5750. if(!this.destroying){
  5751. // If a single form Field, remove it
  5752. if(this.isField(c)){
  5753. this.form.remove(c);
  5754. // If a Container, its already destroyed by the time it gets here. Remove any references to destroyed fields.
  5755. }else if (c.findBy){
  5756. Ext.each(c.findBy(this.isField), this.form.remove, this.form);
  5757. /*
  5758. * This isn't the most efficient way of getting rid of the items, however it's the most
  5759. * correct, which in this case is most important.
  5760. */
  5761. this.form.cleanDestroyed();
  5762. }
  5763. }
  5764. },
  5765. /**
  5766. * Starts monitoring of the valid state of this form. Usually this is done by passing the config
  5767. * option "monitorValid"
  5768. */
  5769. startMonitoring : function(){
  5770. if(!this.validTask){
  5771. this.validTask = new Ext.util.TaskRunner();
  5772. this.validTask.start({
  5773. run : this.bindHandler,
  5774. interval : this.monitorPoll || 200,
  5775. scope: this
  5776. });
  5777. }
  5778. },
  5779. /**
  5780. * Stops monitoring of the valid state of this form
  5781. */
  5782. stopMonitoring : function(){
  5783. if(this.validTask){
  5784. this.validTask.stopAll();
  5785. this.validTask = null;
  5786. }
  5787. },
  5788. /**
  5789. * This is a proxy for the underlying BasicForm's {@link Ext.form.BasicForm#load} call.
  5790. * @param {Object} options The options to pass to the action (see {@link Ext.form.BasicForm#doAction} for details)
  5791. */
  5792. load : function(){
  5793. this.form.load.apply(this.form, arguments);
  5794. },
  5795. // private
  5796. onDisable : function(){
  5797. Ext.FormPanel.superclass.onDisable.call(this);
  5798. if(this.form){
  5799. this.form.items.each(function(){
  5800. this.disable();
  5801. });
  5802. }
  5803. },
  5804. // private
  5805. onEnable : function(){
  5806. Ext.FormPanel.superclass.onEnable.call(this);
  5807. if(this.form){
  5808. this.form.items.each(function(){
  5809. this.enable();
  5810. });
  5811. }
  5812. },
  5813. // private
  5814. bindHandler : function(){
  5815. var valid = true;
  5816. this.form.items.each(function(f){
  5817. if(!f.isValid(true)){
  5818. valid = false;
  5819. return false;
  5820. }
  5821. });
  5822. if(this.fbar){
  5823. var fitems = this.fbar.items.items;
  5824. for(var i = 0, len = fitems.length; i < len; i++){
  5825. var btn = fitems[i];
  5826. if(btn.formBind === true && btn.disabled === valid){
  5827. btn.setDisabled(!valid);
  5828. }
  5829. }
  5830. }
  5831. this.fireEvent('clientvalidation', this, valid);
  5832. }
  5833. });
  5834. Ext.reg('form', Ext.FormPanel);
  5835. Ext.form.FormPanel = Ext.FormPanel;
  5836. /**
  5837. * @class Ext.form.FieldSet
  5838. * @extends Ext.Panel
  5839. * Standard container used for grouping items within a {@link Ext.form.FormPanel form}.
  5840. * <pre><code>
  5841. var form = new Ext.FormPanel({
  5842. title: 'Simple Form with FieldSets',
  5843. labelWidth: 75, // label settings here cascade unless overridden
  5844. url: 'save-form.php',
  5845. frame:true,
  5846. bodyStyle:'padding:5px 5px 0',
  5847. width: 700,
  5848. renderTo: document.body,
  5849. layout:'column', // arrange items in columns
  5850. defaults: { // defaults applied to items
  5851. layout: 'form',
  5852. border: false,
  5853. bodyStyle: 'padding:4px'
  5854. },
  5855. items: [{
  5856. // Fieldset in Column 1
  5857. xtype:'fieldset',
  5858. columnWidth: 0.5,
  5859. title: 'Fieldset 1',
  5860. collapsible: true,
  5861. autoHeight:true,
  5862. defaults: {
  5863. anchor: '-20' // leave room for error icon
  5864. },
  5865. defaultType: 'textfield',
  5866. items :[{
  5867. fieldLabel: 'Field 1'
  5868. }, {
  5869. fieldLabel: 'Field 2'
  5870. }, {
  5871. fieldLabel: 'Field 3'
  5872. }
  5873. ]
  5874. },{
  5875. // Fieldset in Column 2 - Panel inside
  5876. xtype:'fieldset',
  5877. title: 'Show Panel', // title, header, or checkboxToggle creates fieldset header
  5878. autoHeight:true,
  5879. columnWidth: 0.5,
  5880. checkboxToggle: true,
  5881. collapsed: true, // fieldset initially collapsed
  5882. layout:'anchor',
  5883. items :[{
  5884. xtype: 'panel',
  5885. anchor: '100%',
  5886. title: 'Panel inside a fieldset',
  5887. frame: true,
  5888. height: 100
  5889. }]
  5890. }]
  5891. });
  5892. * </code></pre>
  5893. * @constructor
  5894. * @param {Object} config Configuration options
  5895. * @xtype fieldset
  5896. */
  5897. Ext.form.FieldSet = Ext.extend(Ext.Panel, {
  5898. /**
  5899. * @cfg {Mixed} checkboxToggle <tt>true</tt> to render a checkbox into the fieldset frame just
  5900. * in front of the legend to expand/collapse the fieldset when the checkbox is toggled. (defaults
  5901. * to <tt>false</tt>).
  5902. * <p>A {@link Ext.DomHelper DomHelper} element spec may also be specified to create the checkbox.
  5903. * If <tt>true</tt> is specified, the default DomHelper config object used to create the element
  5904. * is:</p><pre><code>
  5905. * {tag: 'input', type: 'checkbox', name: this.checkboxName || this.id+'-checkbox'}
  5906. * </code></pre>
  5907. */
  5908. /**
  5909. * @cfg {String} checkboxName The name to assign to the fieldset's checkbox if <tt>{@link #checkboxToggle} = true</tt>
  5910. * (defaults to <tt>'[checkbox id]-checkbox'</tt>).
  5911. */
  5912. /**
  5913. * @cfg {Boolean} collapsible
  5914. * <tt>true</tt> to make the fieldset collapsible and have the expand/collapse toggle button automatically
  5915. * rendered into the legend element, <tt>false</tt> to keep the fieldset statically sized with no collapse
  5916. * button (defaults to <tt>false</tt>). Another option is to configure <tt>{@link #checkboxToggle}</tt>.
  5917. */
  5918. /**
  5919. * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
  5920. */
  5921. /**
  5922. * @cfg {String} itemCls A css class to apply to the <tt>x-form-item</tt> of fields (see
  5923. * {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl} for details).
  5924. * This property cascades to child containers.
  5925. */
  5926. /**
  5927. * @cfg {String} baseCls The base CSS class applied to the fieldset (defaults to <tt>'x-fieldset'</tt>).
  5928. */
  5929. baseCls : 'x-fieldset',
  5930. /**
  5931. * @cfg {String} layout The {@link Ext.Container#layout} to use inside the fieldset (defaults to <tt>'form'</tt>).
  5932. */
  5933. layout : 'form',
  5934. /**
  5935. * @cfg {Boolean} animCollapse
  5936. * <tt>true</tt> to animate the transition when the panel is collapsed, <tt>false</tt> to skip the
  5937. * animation (defaults to <tt>false</tt>).
  5938. */
  5939. animCollapse : false,
  5940. // private
  5941. onRender : function(ct, position){
  5942. if(!this.el){
  5943. this.el = document.createElement('fieldset');
  5944. this.el.id = this.id;
  5945. if (this.title || this.header || this.checkboxToggle) {
  5946. this.el.appendChild(document.createElement('legend')).className = this.baseCls + '-header';
  5947. }
  5948. }
  5949. Ext.form.FieldSet.superclass.onRender.call(this, ct, position);
  5950. if(this.checkboxToggle){
  5951. var o = typeof this.checkboxToggle == 'object' ?
  5952. this.checkboxToggle :
  5953. {tag: 'input', type: 'checkbox', name: this.checkboxName || this.id+'-checkbox'};
  5954. this.checkbox = this.header.insertFirst(o);
  5955. this.checkbox.dom.checked = !this.collapsed;
  5956. this.mon(this.checkbox, 'click', this.onCheckClick, this);
  5957. }
  5958. },
  5959. // private
  5960. onCollapse : function(doAnim, animArg){
  5961. if(this.checkbox){
  5962. this.checkbox.dom.checked = false;
  5963. }
  5964. Ext.form.FieldSet.superclass.onCollapse.call(this, doAnim, animArg);
  5965. },
  5966. // private
  5967. onExpand : function(doAnim, animArg){
  5968. if(this.checkbox){
  5969. this.checkbox.dom.checked = true;
  5970. }
  5971. Ext.form.FieldSet.superclass.onExpand.call(this, doAnim, animArg);
  5972. },
  5973. /**
  5974. * This function is called by the fieldset's checkbox when it is toggled (only applies when
  5975. * checkboxToggle = true). This method should never be called externally, but can be
  5976. * overridden to provide custom behavior when the checkbox is toggled if needed.
  5977. */
  5978. onCheckClick : function(){
  5979. this[this.checkbox.dom.checked ? 'expand' : 'collapse']();
  5980. }
  5981. /**
  5982. * @cfg {String/Number} activeItem
  5983. * @hide
  5984. */
  5985. /**
  5986. * @cfg {Mixed} applyTo
  5987. * @hide
  5988. */
  5989. /**
  5990. * @cfg {Boolean} bodyBorder
  5991. * @hide
  5992. */
  5993. /**
  5994. * @cfg {Boolean} border
  5995. * @hide
  5996. */
  5997. /**
  5998. * @cfg {Boolean/Number} bufferResize
  5999. * @hide
  6000. */
  6001. /**
  6002. * @cfg {Boolean} collapseFirst
  6003. * @hide
  6004. */
  6005. /**
  6006. * @cfg {String} defaultType
  6007. * @hide
  6008. */
  6009. /**
  6010. * @cfg {String} disabledClass
  6011. * @hide
  6012. */
  6013. /**
  6014. * @cfg {String} elements
  6015. * @hide
  6016. */
  6017. /**
  6018. * @cfg {Boolean} floating
  6019. * @hide
  6020. */
  6021. /**
  6022. * @cfg {Boolean} footer
  6023. * @hide
  6024. */
  6025. /**
  6026. * @cfg {Boolean} frame
  6027. * @hide
  6028. */
  6029. /**
  6030. * @cfg {Boolean} header
  6031. * @hide
  6032. */
  6033. /**
  6034. * @cfg {Boolean} headerAsText
  6035. * @hide
  6036. */
  6037. /**
  6038. * @cfg {Boolean} hideCollapseTool
  6039. * @hide
  6040. */
  6041. /**
  6042. * @cfg {String} iconCls
  6043. * @hide
  6044. */
  6045. /**
  6046. * @cfg {Boolean/String} shadow
  6047. * @hide
  6048. */
  6049. /**
  6050. * @cfg {Number} shadowOffset
  6051. * @hide
  6052. */
  6053. /**
  6054. * @cfg {Boolean} shim
  6055. * @hide
  6056. */
  6057. /**
  6058. * @cfg {Object/Array} tbar
  6059. * @hide
  6060. */
  6061. /**
  6062. * @cfg {Array} tools
  6063. * @hide
  6064. */
  6065. /**
  6066. * @cfg {Ext.Template/Ext.XTemplate} toolTemplate
  6067. * @hide
  6068. */
  6069. /**
  6070. * @cfg {String} xtype
  6071. * @hide
  6072. */
  6073. /**
  6074. * @property header
  6075. * @hide
  6076. */
  6077. /**
  6078. * @property footer
  6079. * @hide
  6080. */
  6081. /**
  6082. * @method focus
  6083. * @hide
  6084. */
  6085. /**
  6086. * @method getBottomToolbar
  6087. * @hide
  6088. */
  6089. /**
  6090. * @method getTopToolbar
  6091. * @hide
  6092. */
  6093. /**
  6094. * @method setIconClass
  6095. * @hide
  6096. */
  6097. /**
  6098. * @event activate
  6099. * @hide
  6100. */
  6101. /**
  6102. * @event beforeclose
  6103. * @hide
  6104. */
  6105. /**
  6106. * @event bodyresize
  6107. * @hide
  6108. */
  6109. /**
  6110. * @event close
  6111. * @hide
  6112. */
  6113. /**
  6114. * @event deactivate
  6115. * @hide
  6116. */
  6117. });
  6118. Ext.reg('fieldset', Ext.form.FieldSet);/**
  6119. * @class Ext.form.HtmlEditor
  6120. * @extends Ext.form.Field
  6121. * Provides a lightweight HTML Editor component. Some toolbar features are not supported by Safari and will be
  6122. * automatically hidden when needed. These are noted in the config options where appropriate.
  6123. * <br><br>The editor's toolbar buttons have tooltips defined in the {@link #buttonTips} property, but they are not
  6124. * enabled by default unless the global {@link Ext.QuickTips} singleton is {@link Ext.QuickTips#init initialized}.
  6125. * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
  6126. * supported by this editor.</b>
  6127. * <br><br>An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
  6128. * any element that has display set to 'none' can cause problems in Safari and Firefox due to their default iframe reloading bugs.
  6129. * <br><br>Example usage:
  6130. * <pre><code>
  6131. // Simple example rendered with default options:
  6132. Ext.QuickTips.init(); // enable tooltips
  6133. new Ext.form.HtmlEditor({
  6134. renderTo: Ext.getBody(),
  6135. width: 800,
  6136. height: 300
  6137. });
  6138. // Passed via xtype into a container and with custom options:
  6139. Ext.QuickTips.init(); // enable tooltips
  6140. new Ext.Panel({
  6141. title: 'HTML Editor',
  6142. renderTo: Ext.getBody(),
  6143. width: 600,
  6144. height: 300,
  6145. frame: true,
  6146. layout: 'fit',
  6147. items: {
  6148. xtype: 'htmleditor',
  6149. enableColors: false,
  6150. enableAlignments: false
  6151. }
  6152. });
  6153. </code></pre>
  6154. * @constructor
  6155. * Create a new HtmlEditor
  6156. * @param {Object} config
  6157. * @xtype htmleditor
  6158. */
  6159. Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, {
  6160. /**
  6161. * @cfg {Boolean} enableFormat Enable the bold, italic and underline buttons (defaults to true)
  6162. */
  6163. enableFormat : true,
  6164. /**
  6165. * @cfg {Boolean} enableFontSize Enable the increase/decrease font size buttons (defaults to true)
  6166. */
  6167. enableFontSize : true,
  6168. /**
  6169. * @cfg {Boolean} enableColors Enable the fore/highlight color buttons (defaults to true)
  6170. */
  6171. enableColors : true,
  6172. /**
  6173. * @cfg {Boolean} enableAlignments Enable the left, center, right alignment buttons (defaults to true)
  6174. */
  6175. enableAlignments : true,
  6176. /**
  6177. * @cfg {Boolean} enableLists Enable the bullet and numbered list buttons. Not available in Safari. (defaults to true)
  6178. */
  6179. enableLists : true,
  6180. /**
  6181. * @cfg {Boolean} enableSourceEdit Enable the switch to source edit button. Not available in Safari. (defaults to true)
  6182. */
  6183. enableSourceEdit : true,
  6184. /**
  6185. * @cfg {Boolean} enableLinks Enable the create link button. Not available in Safari. (defaults to true)
  6186. */
  6187. enableLinks : true,
  6188. /**
  6189. * @cfg {Boolean} enableFont Enable font selection. Not available in Safari. (defaults to true)
  6190. */
  6191. enableFont : true,
  6192. /**
  6193. * @cfg {String} createLinkText The default text for the create link prompt
  6194. */
  6195. createLinkText : 'Please enter the URL for the link:',
  6196. /**
  6197. * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
  6198. */
  6199. defaultLinkValue : 'http:/'+'/',
  6200. /**
  6201. * @cfg {Array} fontFamilies An array of available font families
  6202. */
  6203. fontFamilies : [
  6204. 'Arial',
  6205. 'Courier New',
  6206. 'Tahoma',
  6207. 'Times New Roman',
  6208. 'Verdana'
  6209. ],
  6210. defaultFont: 'tahoma',
  6211. /**
  6212. * @cfg {String} defaultValue A default value to be put into the editor to resolve focus issues (defaults to &#160; (Non-breaking space) in Opera and IE6, &#8203; (Zero-width space) in all other browsers).
  6213. */
  6214. defaultValue: (Ext.isOpera || Ext.isIE6) ? '&#160;' : '&#8203;',
  6215. // private properties
  6216. actionMode: 'wrap',
  6217. validationEvent : false,
  6218. deferHeight: true,
  6219. initialized : false,
  6220. activated : false,
  6221. sourceEditMode : false,
  6222. onFocus : Ext.emptyFn,
  6223. iframePad:3,
  6224. hideMode:'offsets',
  6225. defaultAutoCreate : {
  6226. tag: "textarea",
  6227. style:"width:500px;height:300px;",
  6228. autocomplete: "off"
  6229. },
  6230. // private
  6231. initComponent : function(){
  6232. this.addEvents(
  6233. /**
  6234. * @event initialize
  6235. * Fires when the editor is fully initialized (including the iframe)
  6236. * @param {HtmlEditor} this
  6237. */
  6238. 'initialize',
  6239. /**
  6240. * @event activate
  6241. * Fires when the editor is first receives the focus. Any insertion must wait
  6242. * until after this event.
  6243. * @param {HtmlEditor} this
  6244. */
  6245. 'activate',
  6246. /**
  6247. * @event beforesync
  6248. * Fires before the textarea is updated with content from the editor iframe. Return false
  6249. * to cancel the sync.
  6250. * @param {HtmlEditor} this
  6251. * @param {String} html
  6252. */
  6253. 'beforesync',
  6254. /**
  6255. * @event beforepush
  6256. * Fires before the iframe editor is updated with content from the textarea. Return false
  6257. * to cancel the push.
  6258. * @param {HtmlEditor} this
  6259. * @param {String} html
  6260. */
  6261. 'beforepush',
  6262. /**
  6263. * @event sync
  6264. * Fires when the textarea is updated with content from the editor iframe.
  6265. * @param {HtmlEditor} this
  6266. * @param {String} html
  6267. */
  6268. 'sync',
  6269. /**
  6270. * @event push
  6271. * Fires when the iframe editor is updated with content from the textarea.
  6272. * @param {HtmlEditor} this
  6273. * @param {String} html
  6274. */
  6275. 'push',
  6276. /**
  6277. * @event editmodechange
  6278. * Fires when the editor switches edit modes
  6279. * @param {HtmlEditor} this
  6280. * @param {Boolean} sourceEdit True if source edit, false if standard editing.
  6281. */
  6282. 'editmodechange'
  6283. );
  6284. Ext.form.HtmlEditor.superclass.initComponent.call(this);
  6285. },
  6286. // private
  6287. createFontOptions : function(){
  6288. var buf = [], fs = this.fontFamilies, ff, lc;
  6289. for(var i = 0, len = fs.length; i< len; i++){
  6290. ff = fs[i];
  6291. lc = ff.toLowerCase();
  6292. buf.push(
  6293. '<option value="',lc,'" style="font-family:',ff,';"',
  6294. (this.defaultFont == lc ? ' selected="true">' : '>'),
  6295. ff,
  6296. '</option>'
  6297. );
  6298. }
  6299. return buf.join('');
  6300. },
  6301. /*
  6302. * Protected method that will not generally be called directly. It
  6303. * is called when the editor creates its toolbar. Override this method if you need to
  6304. * add custom toolbar buttons.
  6305. * @param {HtmlEditor} editor
  6306. */
  6307. createToolbar : function(editor){
  6308. var items = [];
  6309. var tipsEnabled = Ext.QuickTips && Ext.QuickTips.isEnabled();
  6310. function btn(id, toggle, handler){
  6311. return {
  6312. itemId : id,
  6313. cls : 'x-btn-icon',
  6314. iconCls: 'x-edit-'+id,
  6315. enableToggle:toggle !== false,
  6316. scope: editor,
  6317. handler:handler||editor.relayBtnCmd,
  6318. clickEvent:'mousedown',
  6319. tooltip: tipsEnabled ? editor.buttonTips[id] || undefined : undefined,
  6320. overflowText: editor.buttonTips[id].title || undefined,
  6321. tabIndex:-1
  6322. };
  6323. }
  6324. if(this.enableFont && !Ext.isSafari2){
  6325. var fontSelectItem = new Ext.Toolbar.Item({
  6326. autoEl: {
  6327. tag:'select',
  6328. cls:'x-font-select',
  6329. html: this.createFontOptions()
  6330. }
  6331. });
  6332. items.push(
  6333. fontSelectItem,
  6334. '-'
  6335. );
  6336. }
  6337. if(this.enableFormat){
  6338. items.push(
  6339. btn('bold'),
  6340. btn('italic'),
  6341. btn('underline')
  6342. );
  6343. }
  6344. if(this.enableFontSize){
  6345. items.push(
  6346. '-',
  6347. btn('increasefontsize', false, this.adjustFont),
  6348. btn('decreasefontsize', false, this.adjustFont)
  6349. );
  6350. }
  6351. if(this.enableColors){
  6352. items.push(
  6353. '-', {
  6354. itemId:'forecolor',
  6355. cls:'x-btn-icon',
  6356. iconCls: 'x-edit-forecolor',
  6357. clickEvent:'mousedown',
  6358. tooltip: tipsEnabled ? editor.buttonTips.forecolor || undefined : undefined,
  6359. tabIndex:-1,
  6360. menu : new Ext.menu.ColorMenu({
  6361. allowReselect: true,
  6362. focus: Ext.emptyFn,
  6363. value:'000000',
  6364. plain:true,
  6365. listeners: {
  6366. scope: this,
  6367. select: function(cp, color){
  6368. this.execCmd('forecolor', Ext.isWebKit || Ext.isIE ? '#'+color : color);
  6369. this.deferFocus();
  6370. }
  6371. },
  6372. clickEvent:'mousedown'
  6373. })
  6374. }, {
  6375. itemId:'backcolor',
  6376. cls:'x-btn-icon',
  6377. iconCls: 'x-edit-backcolor',
  6378. clickEvent:'mousedown',
  6379. tooltip: tipsEnabled ? editor.buttonTips.backcolor || undefined : undefined,
  6380. tabIndex:-1,
  6381. menu : new Ext.menu.ColorMenu({
  6382. focus: Ext.emptyFn,
  6383. value:'FFFFFF',
  6384. plain:true,
  6385. allowReselect: true,
  6386. listeners: {
  6387. scope: this,
  6388. select: function(cp, color){
  6389. if(Ext.isGecko){
  6390. this.execCmd('useCSS', false);
  6391. this.execCmd('hilitecolor', color);
  6392. this.execCmd('useCSS', true);
  6393. this.deferFocus();
  6394. }else{
  6395. this.execCmd(Ext.isOpera ? 'hilitecolor' : 'backcolor', Ext.isWebKit || Ext.isIE ? '#'+color : color);
  6396. this.deferFocus();
  6397. }
  6398. }
  6399. },
  6400. clickEvent:'mousedown'
  6401. })
  6402. }
  6403. );
  6404. }
  6405. if(this.enableAlignments){
  6406. items.push(
  6407. '-',
  6408. btn('justifyleft'),
  6409. btn('justifycenter'),
  6410. btn('justifyright')
  6411. );
  6412. }
  6413. if(!Ext.isSafari2){
  6414. if(this.enableLinks){
  6415. items.push(
  6416. '-',
  6417. btn('createlink', false, this.createLink)
  6418. );
  6419. }
  6420. if(this.enableLists){
  6421. items.push(
  6422. '-',
  6423. btn('insertorderedlist'),
  6424. btn('insertunorderedlist')
  6425. );
  6426. }
  6427. if(this.enableSourceEdit){
  6428. items.push(
  6429. '-',
  6430. btn('sourceedit', true, function(btn){
  6431. this.toggleSourceEdit(!this.sourceEditMode);
  6432. })
  6433. );
  6434. }
  6435. }
  6436. // build the toolbar
  6437. var tb = new Ext.Toolbar({
  6438. renderTo: this.wrap.dom.firstChild,
  6439. items: items
  6440. });
  6441. if (fontSelectItem) {
  6442. this.fontSelect = fontSelectItem.el;
  6443. this.mon(this.fontSelect, 'change', function(){
  6444. var font = this.fontSelect.dom.value;
  6445. this.relayCmd('fontname', font);
  6446. this.deferFocus();
  6447. }, this);
  6448. }
  6449. // stop form submits
  6450. this.mon(tb.el, 'click', function(e){
  6451. e.preventDefault();
  6452. });
  6453. this.tb = tb;
  6454. this.tb.doLayout();
  6455. },
  6456. onDisable: function(){
  6457. this.wrap.mask();
  6458. Ext.form.HtmlEditor.superclass.onDisable.call(this);
  6459. },
  6460. onEnable: function(){
  6461. this.wrap.unmask();
  6462. Ext.form.HtmlEditor.superclass.onEnable.call(this);
  6463. },
  6464. setReadOnly: function(readOnly){
  6465. Ext.form.HtmlEditor.superclass.setReadOnly.call(this, readOnly);
  6466. if(this.initialized){
  6467. if(Ext.isIE){
  6468. this.getEditorBody().contentEditable = !readOnly;
  6469. }else{
  6470. this.setDesignMode(!readOnly);
  6471. }
  6472. var bd = this.getEditorBody();
  6473. if(bd){
  6474. bd.style.cursor = this.readOnly ? 'default' : 'text';
  6475. }
  6476. this.disableItems(readOnly);
  6477. }
  6478. },
  6479. /**
  6480. * Protected method that will not generally be called directly. It
  6481. * is called when the editor initializes the iframe with HTML contents. Override this method if you
  6482. * want to change the initialization markup of the iframe (e.g. to add stylesheets).
  6483. *
  6484. * Note: IE8-Standards has unwanted scroller behavior, so the default meta tag forces IE7 compatibility
  6485. */
  6486. getDocMarkup : function(){
  6487. var h = Ext.fly(this.iframe).getHeight() - this.iframePad * 2;
  6488. return String.format('<html><head><style type="text/css">body{border: 0; margin: 0; padding: {0}px; height: {1}px; cursor: text}</style></head><body></body></html>', this.iframePad, h);
  6489. },
  6490. // private
  6491. getEditorBody : function(){
  6492. var doc = this.getDoc();
  6493. return doc.body || doc.documentElement;
  6494. },
  6495. // private
  6496. getDoc : function(){
  6497. return Ext.isIE ? this.getWin().document : (this.iframe.contentDocument || this.getWin().document);
  6498. },
  6499. // private
  6500. getWin : function(){
  6501. return Ext.isIE ? this.iframe.contentWindow : window.frames[this.iframe.name];
  6502. },
  6503. // private
  6504. onRender : function(ct, position){
  6505. Ext.form.HtmlEditor.superclass.onRender.call(this, ct, position);
  6506. this.el.dom.style.border = '0 none';
  6507. this.el.dom.setAttribute('tabIndex', -1);
  6508. this.el.addClass('x-hidden');
  6509. if(Ext.isIE){ // fix IE 1px bogus margin
  6510. this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;');
  6511. }
  6512. this.wrap = this.el.wrap({
  6513. cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
  6514. });
  6515. this.createToolbar(this);
  6516. this.disableItems(true);
  6517. this.tb.doLayout();
  6518. this.createIFrame();
  6519. if(!this.width){
  6520. var sz = this.el.getSize();
  6521. this.setSize(sz.width, this.height || sz.height);
  6522. }
  6523. this.resizeEl = this.positionEl = this.wrap;
  6524. },
  6525. createIFrame: function(){
  6526. var iframe = document.createElement('iframe');
  6527. iframe.name = Ext.id();
  6528. iframe.frameBorder = '0';
  6529. iframe.style.overflow = 'auto';
  6530. iframe.src = Ext.SSL_SECURE_URL;
  6531. this.wrap.dom.appendChild(iframe);
  6532. this.iframe = iframe;
  6533. this.monitorTask = Ext.TaskMgr.start({
  6534. run: this.checkDesignMode,
  6535. scope: this,
  6536. interval:100
  6537. });
  6538. },
  6539. initFrame : function(){
  6540. Ext.TaskMgr.stop(this.monitorTask);
  6541. var doc = this.getDoc();
  6542. this.win = this.getWin();
  6543. doc.open();
  6544. doc.write(this.getDocMarkup());
  6545. doc.close();
  6546. this.readyTask = { // must defer to wait for browser to be ready
  6547. run : function(){
  6548. var doc = this.getDoc();
  6549. if(doc.body || doc.readyState == 'complete'){
  6550. Ext.TaskMgr.stop(this.readyTask);
  6551. this.setDesignMode(true);
  6552. this.initEditor.defer(10, this);
  6553. }
  6554. },
  6555. interval : 10,
  6556. duration:10000,
  6557. scope: this
  6558. };
  6559. Ext.TaskMgr.start(this.readyTask);
  6560. },
  6561. checkDesignMode : function(){
  6562. if(this.wrap && this.wrap.dom.offsetWidth){
  6563. var doc = this.getDoc();
  6564. if(!doc){
  6565. return;
  6566. }
  6567. if(!doc.editorInitialized || this.getDesignMode() != 'on'){
  6568. this.initFrame();
  6569. }
  6570. }
  6571. },
  6572. /* private
  6573. * set current design mode. To enable, mode can be true or 'on', off otherwise
  6574. */
  6575. setDesignMode : function(mode){
  6576. var doc = this.getDoc();
  6577. if (doc) {
  6578. if(this.readOnly){
  6579. mode = false;
  6580. }
  6581. doc.designMode = (/on|true/i).test(String(mode).toLowerCase()) ?'on':'off';
  6582. }
  6583. },
  6584. // private
  6585. getDesignMode : function(){
  6586. var doc = this.getDoc();
  6587. if(!doc){ return ''; }
  6588. return String(doc.designMode).toLowerCase();
  6589. },
  6590. disableItems: function(disabled){
  6591. if(this.fontSelect){
  6592. this.fontSelect.dom.disabled = disabled;
  6593. }
  6594. this.tb.items.each(function(item){
  6595. if(item.getItemId() != 'sourceedit'){
  6596. item.setDisabled(disabled);
  6597. }
  6598. });
  6599. },
  6600. // private
  6601. onResize : function(w, h){
  6602. Ext.form.HtmlEditor.superclass.onResize.apply(this, arguments);
  6603. if(this.el && this.iframe){
  6604. if(Ext.isNumber(w)){
  6605. var aw = w - this.wrap.getFrameWidth('lr');
  6606. this.el.setWidth(aw);
  6607. this.tb.setWidth(aw);
  6608. this.iframe.style.width = Math.max(aw, 0) + 'px';
  6609. }
  6610. if(Ext.isNumber(h)){
  6611. var ah = h - this.wrap.getFrameWidth('tb') - this.tb.el.getHeight();
  6612. this.el.setHeight(ah);
  6613. this.iframe.style.height = Math.max(ah, 0) + 'px';
  6614. var bd = this.getEditorBody();
  6615. if(bd){
  6616. bd.style.height = Math.max((ah - (this.iframePad*2)), 0) + 'px';
  6617. }
  6618. }
  6619. }
  6620. },
  6621. /**
  6622. * Toggles the editor between standard and source edit mode.
  6623. * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
  6624. */
  6625. toggleSourceEdit : function(sourceEditMode){
  6626. var iframeHeight,
  6627. elHeight;
  6628. if (sourceEditMode === undefined) {
  6629. sourceEditMode = !this.sourceEditMode;
  6630. }
  6631. this.sourceEditMode = sourceEditMode === true;
  6632. var btn = this.tb.getComponent('sourceedit');
  6633. if (btn.pressed !== this.sourceEditMode) {
  6634. btn.toggle(this.sourceEditMode);
  6635. if (!btn.xtbHidden) {
  6636. return;
  6637. }
  6638. }
  6639. if (this.sourceEditMode) {
  6640. // grab the height of the containing panel before we hide the iframe
  6641. this.previousSize = this.getSize();
  6642. iframeHeight = Ext.get(this.iframe).getHeight();
  6643. this.disableItems(true);
  6644. this.syncValue();
  6645. this.iframe.className = 'x-hidden';
  6646. this.el.removeClass('x-hidden');
  6647. this.el.dom.removeAttribute('tabIndex');
  6648. this.el.focus();
  6649. this.el.dom.style.height = iframeHeight + 'px';
  6650. }
  6651. else {
  6652. elHeight = parseInt(this.el.dom.style.height, 10);
  6653. if (this.initialized) {
  6654. this.disableItems(this.readOnly);
  6655. }
  6656. this.pushValue();
  6657. this.iframe.className = '';
  6658. this.el.addClass('x-hidden');
  6659. this.el.dom.setAttribute('tabIndex', -1);
  6660. this.deferFocus();
  6661. this.setSize(this.previousSize);
  6662. delete this.previousSize;
  6663. this.iframe.style.height = elHeight + 'px';
  6664. }
  6665. this.fireEvent('editmodechange', this, this.sourceEditMode);
  6666. },
  6667. // private used internally
  6668. createLink : function() {
  6669. var url = prompt(this.createLinkText, this.defaultLinkValue);
  6670. if(url && url != 'http:/'+'/'){
  6671. this.relayCmd('createlink', url);
  6672. }
  6673. },
  6674. // private
  6675. initEvents : function(){
  6676. this.originalValue = this.getValue();
  6677. },
  6678. /**
  6679. * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
  6680. * @method
  6681. */
  6682. markInvalid : Ext.emptyFn,
  6683. /**
  6684. * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
  6685. * @method
  6686. */
  6687. clearInvalid : Ext.emptyFn,
  6688. // docs inherit from Field
  6689. setValue : function(v){
  6690. Ext.form.HtmlEditor.superclass.setValue.call(this, v);
  6691. this.pushValue();
  6692. return this;
  6693. },
  6694. /**
  6695. * Protected method that will not generally be called directly. If you need/want
  6696. * custom HTML cleanup, this is the method you should override.
  6697. * @param {String} html The HTML to be cleaned
  6698. * @return {String} The cleaned HTML
  6699. */
  6700. cleanHtml: function(html) {
  6701. html = String(html);
  6702. if(Ext.isWebKit){ // strip safari nonsense
  6703. html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
  6704. }
  6705. /*
  6706. * Neat little hack. Strips out all the non-digit characters from the default
  6707. * value and compares it to the character code of the first character in the string
  6708. * because it can cause encoding issues when posted to the server.
  6709. */
  6710. if(html.charCodeAt(0) == this.defaultValue.replace(/\D/g, '')){
  6711. html = html.substring(1);
  6712. }
  6713. return html;
  6714. },
  6715. /**
  6716. * Protected method that will not generally be called directly. Syncs the contents
  6717. * of the editor iframe with the textarea.
  6718. */
  6719. syncValue : function(){
  6720. if(this.initialized){
  6721. var bd = this.getEditorBody();
  6722. var html = bd.innerHTML;
  6723. if(Ext.isWebKit){
  6724. var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
  6725. var m = bs.match(/text-align:(.*?);/i);
  6726. if(m && m[1]){
  6727. html = '<div style="'+m[0]+'">' + html + '</div>';
  6728. }
  6729. }
  6730. html = this.cleanHtml(html);
  6731. if(this.fireEvent('beforesync', this, html) !== false){
  6732. this.el.dom.value = html;
  6733. this.fireEvent('sync', this, html);
  6734. }
  6735. }
  6736. },
  6737. //docs inherit from Field
  6738. getValue : function() {
  6739. this[this.sourceEditMode ? 'pushValue' : 'syncValue']();
  6740. return Ext.form.HtmlEditor.superclass.getValue.call(this);
  6741. },
  6742. /**
  6743. * Protected method that will not generally be called directly. Pushes the value of the textarea
  6744. * into the iframe editor.
  6745. */
  6746. pushValue : function(){
  6747. if(this.initialized){
  6748. var v = this.el.dom.value;
  6749. if(!this.activated && v.length < 1){
  6750. v = this.defaultValue;
  6751. }
  6752. if(this.fireEvent('beforepush', this, v) !== false){
  6753. this.getEditorBody().innerHTML = v;
  6754. if(Ext.isGecko){
  6755. // Gecko hack, see: https://bugzilla.mozilla.org/show_bug.cgi?id=232791#c8
  6756. this.setDesignMode(false); //toggle off first
  6757. this.setDesignMode(true);
  6758. }
  6759. this.fireEvent('push', this, v);
  6760. }
  6761. }
  6762. },
  6763. // private
  6764. deferFocus : function(){
  6765. this.focus.defer(10, this);
  6766. },
  6767. // docs inherit from Field
  6768. focus : function(){
  6769. if(this.win && !this.sourceEditMode){
  6770. this.win.focus();
  6771. }else{
  6772. this.el.focus();
  6773. }
  6774. },
  6775. // private
  6776. initEditor : function(){
  6777. //Destroying the component during/before initEditor can cause issues.
  6778. try{
  6779. var dbody = this.getEditorBody(),
  6780. ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat', 'background-color', 'color'),
  6781. doc,
  6782. fn;
  6783. ss['background-attachment'] = 'fixed'; // w3c
  6784. dbody.bgProperties = 'fixed'; // ie
  6785. Ext.DomHelper.applyStyles(dbody, ss);
  6786. doc = this.getDoc();
  6787. if(doc){
  6788. try{
  6789. Ext.EventManager.removeAll(doc);
  6790. }catch(e){}
  6791. }
  6792. /*
  6793. * We need to use createDelegate here, because when using buffer, the delayed task is added
  6794. * as a property to the function. When the listener is removed, the task is deleted from the function.
  6795. * Since onEditorEvent is shared on the prototype, if we have multiple html editors, the first time one of the editors
  6796. * is destroyed, it causes the fn to be deleted from the prototype, which causes errors. Essentially, we're just anonymizing the function.
  6797. */
  6798. fn = this.onEditorEvent.createDelegate(this);
  6799. Ext.EventManager.on(doc, {
  6800. mousedown: fn,
  6801. dblclick: fn,
  6802. click: fn,
  6803. keyup: fn,
  6804. buffer:100
  6805. });
  6806. if(Ext.isGecko){
  6807. Ext.EventManager.on(doc, 'keypress', this.applyCommand, this);
  6808. }
  6809. if(Ext.isIE || Ext.isWebKit || Ext.isOpera){
  6810. Ext.EventManager.on(doc, 'keydown', this.fixKeys, this);
  6811. }
  6812. doc.editorInitialized = true;
  6813. this.initialized = true;
  6814. this.pushValue();
  6815. this.setReadOnly(this.readOnly);
  6816. this.fireEvent('initialize', this);
  6817. }catch(e){}
  6818. },
  6819. // private
  6820. beforeDestroy : function(){
  6821. if(this.monitorTask){
  6822. Ext.TaskMgr.stop(this.monitorTask);
  6823. }
  6824. if(this.readyTask){
  6825. Ext.TaskMgr.stop(this.readyTask);
  6826. }
  6827. if(this.rendered){
  6828. Ext.destroy(this.tb);
  6829. var doc = this.getDoc();
  6830. Ext.EventManager.removeFromSpecialCache(doc);
  6831. if(doc){
  6832. try{
  6833. Ext.EventManager.removeAll(doc);
  6834. for (var prop in doc){
  6835. delete doc[prop];
  6836. }
  6837. }catch(e){}
  6838. }
  6839. if(this.wrap){
  6840. this.wrap.dom.innerHTML = '';
  6841. this.wrap.remove();
  6842. }
  6843. }
  6844. Ext.form.HtmlEditor.superclass.beforeDestroy.call(this);
  6845. },
  6846. // private
  6847. onFirstFocus : function(){
  6848. this.activated = true;
  6849. this.disableItems(this.readOnly);
  6850. if(Ext.isGecko){ // prevent silly gecko errors
  6851. this.win.focus();
  6852. var s = this.win.getSelection();
  6853. if(!s.focusNode || s.focusNode.nodeType != 3){
  6854. var r = s.getRangeAt(0);
  6855. r.selectNodeContents(this.getEditorBody());
  6856. r.collapse(true);
  6857. this.deferFocus();
  6858. }
  6859. try{
  6860. this.execCmd('useCSS', true);
  6861. this.execCmd('styleWithCSS', false);
  6862. }catch(e){}
  6863. }
  6864. this.fireEvent('activate', this);
  6865. },
  6866. // private
  6867. adjustFont: function(btn){
  6868. var adjust = btn.getItemId() == 'increasefontsize' ? 1 : -1,
  6869. doc = this.getDoc(),
  6870. v = parseInt(doc.queryCommandValue('FontSize') || 2, 10);
  6871. if((Ext.isSafari && !Ext.isSafari2) || Ext.isChrome || Ext.isAir){
  6872. // Safari 3 values
  6873. // 1 = 10px, 2 = 13px, 3 = 16px, 4 = 18px, 5 = 24px, 6 = 32px
  6874. if(v <= 10){
  6875. v = 1 + adjust;
  6876. }else if(v <= 13){
  6877. v = 2 + adjust;
  6878. }else if(v <= 16){
  6879. v = 3 + adjust;
  6880. }else if(v <= 18){
  6881. v = 4 + adjust;
  6882. }else if(v <= 24){
  6883. v = 5 + adjust;
  6884. }else {
  6885. v = 6 + adjust;
  6886. }
  6887. v = v.constrain(1, 6);
  6888. }else{
  6889. if(Ext.isSafari){ // safari
  6890. adjust *= 2;
  6891. }
  6892. v = Math.max(1, v+adjust) + (Ext.isSafari ? 'px' : 0);
  6893. }
  6894. this.execCmd('FontSize', v);
  6895. },
  6896. // private
  6897. onEditorEvent : function(e){
  6898. this.updateToolbar();
  6899. },
  6900. /**
  6901. * Protected method that will not generally be called directly. It triggers
  6902. * a toolbar update by reading the markup state of the current selection in the editor.
  6903. */
  6904. updateToolbar: function(){
  6905. if(this.readOnly){
  6906. return;
  6907. }
  6908. if(!this.activated){
  6909. this.onFirstFocus();
  6910. return;
  6911. }
  6912. var btns = this.tb.items.map,
  6913. doc = this.getDoc();
  6914. if(this.enableFont && !Ext.isSafari2){
  6915. var name = (doc.queryCommandValue('FontName')||this.defaultFont).toLowerCase();
  6916. if(name != this.fontSelect.dom.value){
  6917. this.fontSelect.dom.value = name;
  6918. }
  6919. }
  6920. if(this.enableFormat){
  6921. btns.bold.toggle(doc.queryCommandState('bold'));
  6922. btns.italic.toggle(doc.queryCommandState('italic'));
  6923. btns.underline.toggle(doc.queryCommandState('underline'));
  6924. }
  6925. if(this.enableAlignments){
  6926. btns.justifyleft.toggle(doc.queryCommandState('justifyleft'));
  6927. btns.justifycenter.toggle(doc.queryCommandState('justifycenter'));
  6928. btns.justifyright.toggle(doc.queryCommandState('justifyright'));
  6929. }
  6930. if(!Ext.isSafari2 && this.enableLists){
  6931. btns.insertorderedlist.toggle(doc.queryCommandState('insertorderedlist'));
  6932. btns.insertunorderedlist.toggle(doc.queryCommandState('insertunorderedlist'));
  6933. }
  6934. Ext.menu.MenuMgr.hideAll();
  6935. this.syncValue();
  6936. },
  6937. // private
  6938. relayBtnCmd : function(btn){
  6939. this.relayCmd(btn.getItemId());
  6940. },
  6941. /**
  6942. * Executes a Midas editor command on the editor document and performs necessary focus and
  6943. * toolbar updates. <b>This should only be called after the editor is initialized.</b>
  6944. * @param {String} cmd The Midas command
  6945. * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
  6946. */
  6947. relayCmd : function(cmd, value){
  6948. (function(){
  6949. this.focus();
  6950. this.execCmd(cmd, value);
  6951. this.updateToolbar();
  6952. }).defer(10, this);
  6953. },
  6954. /**
  6955. * Executes a Midas editor command directly on the editor document.
  6956. * For visual commands, you should use {@link #relayCmd} instead.
  6957. * <b>This should only be called after the editor is initialized.</b>
  6958. * @param {String} cmd The Midas command
  6959. * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
  6960. */
  6961. execCmd : function(cmd, value){
  6962. var doc = this.getDoc();
  6963. doc.execCommand(cmd, false, value === undefined ? null : value);
  6964. this.syncValue();
  6965. },
  6966. // private
  6967. applyCommand : function(e){
  6968. if(e.ctrlKey){
  6969. var c = e.getCharCode(), cmd;
  6970. if(c > 0){
  6971. c = String.fromCharCode(c);
  6972. switch(c){
  6973. case 'b':
  6974. cmd = 'bold';
  6975. break;
  6976. case 'i':
  6977. cmd = 'italic';
  6978. break;
  6979. case 'u':
  6980. cmd = 'underline';
  6981. break;
  6982. }
  6983. if(cmd){
  6984. this.win.focus();
  6985. this.execCmd(cmd);
  6986. this.deferFocus();
  6987. e.preventDefault();
  6988. }
  6989. }
  6990. }
  6991. },
  6992. /**
  6993. * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
  6994. * to insert text.
  6995. * @param {String} text
  6996. */
  6997. insertAtCursor : function(text){
  6998. if(!this.activated){
  6999. return;
  7000. }
  7001. if(Ext.isIE){
  7002. this.win.focus();
  7003. var doc = this.getDoc(),
  7004. r = doc.selection.createRange();
  7005. if(r){
  7006. r.pasteHTML(text);
  7007. this.syncValue();
  7008. this.deferFocus();
  7009. }
  7010. }else{
  7011. this.win.focus();
  7012. this.execCmd('InsertHTML', text);
  7013. this.deferFocus();
  7014. }
  7015. },
  7016. // private
  7017. fixKeys : function(){ // load time branching for fastest keydown performance
  7018. if(Ext.isIE){
  7019. return function(e){
  7020. var k = e.getKey(),
  7021. doc = this.getDoc(),
  7022. r;
  7023. if(k == e.TAB){
  7024. e.stopEvent();
  7025. r = doc.selection.createRange();
  7026. if(r){
  7027. r.collapse(true);
  7028. r.pasteHTML('&nbsp;&nbsp;&nbsp;&nbsp;');
  7029. this.deferFocus();
  7030. }
  7031. }else if(k == e.ENTER){
  7032. r = doc.selection.createRange();
  7033. if(r){
  7034. var target = r.parentElement();
  7035. if(!target || target.tagName.toLowerCase() != 'li'){
  7036. e.stopEvent();
  7037. r.pasteHTML('<br />');
  7038. r.collapse(false);
  7039. r.select();
  7040. }
  7041. }
  7042. }
  7043. };
  7044. }else if(Ext.isOpera){
  7045. return function(e){
  7046. var k = e.getKey();
  7047. if(k == e.TAB){
  7048. e.stopEvent();
  7049. this.win.focus();
  7050. this.execCmd('InsertHTML','&nbsp;&nbsp;&nbsp;&nbsp;');
  7051. this.deferFocus();
  7052. }
  7053. };
  7054. }else if(Ext.isWebKit){
  7055. return function(e){
  7056. var k = e.getKey();
  7057. if(k == e.TAB){
  7058. e.stopEvent();
  7059. this.execCmd('InsertText','\t');
  7060. this.deferFocus();
  7061. }else if(k == e.ENTER){
  7062. e.stopEvent();
  7063. this.execCmd('InsertHtml','<br /><br />');
  7064. this.deferFocus();
  7065. }
  7066. };
  7067. }
  7068. }(),
  7069. /**
  7070. * Returns the editor's toolbar. <b>This is only available after the editor has been rendered.</b>
  7071. * @return {Ext.Toolbar}
  7072. */
  7073. getToolbar : function(){
  7074. return this.tb;
  7075. },
  7076. /**
  7077. * Object collection of toolbar tooltips for the buttons in the editor. The key
  7078. * is the command id associated with that button and the value is a valid QuickTips object.
  7079. * For example:
  7080. <pre><code>
  7081. {
  7082. bold : {
  7083. title: 'Bold (Ctrl+B)',
  7084. text: 'Make the selected text bold.',
  7085. cls: 'x-html-editor-tip'
  7086. },
  7087. italic : {
  7088. title: 'Italic (Ctrl+I)',
  7089. text: 'Make the selected text italic.',
  7090. cls: 'x-html-editor-tip'
  7091. },
  7092. ...
  7093. </code></pre>
  7094. * @type Object
  7095. */
  7096. buttonTips : {
  7097. bold : {
  7098. title: 'Bold (Ctrl+B)',
  7099. text: 'Make the selected text bold.',
  7100. cls: 'x-html-editor-tip'
  7101. },
  7102. italic : {
  7103. title: 'Italic (Ctrl+I)',
  7104. text: 'Make the selected text italic.',
  7105. cls: 'x-html-editor-tip'
  7106. },
  7107. underline : {
  7108. title: 'Underline (Ctrl+U)',
  7109. text: 'Underline the selected text.',
  7110. cls: 'x-html-editor-tip'
  7111. },
  7112. increasefontsize : {
  7113. title: 'Grow Text',
  7114. text: 'Increase the font size.',
  7115. cls: 'x-html-editor-tip'
  7116. },
  7117. decreasefontsize : {
  7118. title: 'Shrink Text',
  7119. text: 'Decrease the font size.',
  7120. cls: 'x-html-editor-tip'
  7121. },
  7122. backcolor : {
  7123. title: 'Text Highlight Color',
  7124. text: 'Change the background color of the selected text.',
  7125. cls: 'x-html-editor-tip'
  7126. },
  7127. forecolor : {
  7128. title: 'Font Color',
  7129. text: 'Change the color of the selected text.',
  7130. cls: 'x-html-editor-tip'
  7131. },
  7132. justifyleft : {
  7133. title: 'Align Text Left',
  7134. text: 'Align text to the left.',
  7135. cls: 'x-html-editor-tip'
  7136. },
  7137. justifycenter : {
  7138. title: 'Center Text',
  7139. text: 'Center text in the editor.',
  7140. cls: 'x-html-editor-tip'
  7141. },
  7142. justifyright : {
  7143. title: 'Align Text Right',
  7144. text: 'Align text to the right.',
  7145. cls: 'x-html-editor-tip'
  7146. },
  7147. insertunorderedlist : {
  7148. title: 'Bullet List',
  7149. text: 'Start a bulleted list.',
  7150. cls: 'x-html-editor-tip'
  7151. },
  7152. insertorderedlist : {
  7153. title: 'Numbered List',
  7154. text: 'Start a numbered list.',
  7155. cls: 'x-html-editor-tip'
  7156. },
  7157. createlink : {
  7158. title: 'Hyperlink',
  7159. text: 'Make the selected text a hyperlink.',
  7160. cls: 'x-html-editor-tip'
  7161. },
  7162. sourceedit : {
  7163. title: 'Source Edit',
  7164. text: 'Switch to source editing mode.',
  7165. cls: 'x-html-editor-tip'
  7166. }
  7167. }
  7168. // hide stuff that is not compatible
  7169. /**
  7170. * @event blur
  7171. * @hide
  7172. */
  7173. /**
  7174. * @event change
  7175. * @hide
  7176. */
  7177. /**
  7178. * @event focus
  7179. * @hide
  7180. */
  7181. /**
  7182. * @event specialkey
  7183. * @hide
  7184. */
  7185. /**
  7186. * @cfg {String} fieldClass @hide
  7187. */
  7188. /**
  7189. * @cfg {String} focusClass @hide
  7190. */
  7191. /**
  7192. * @cfg {String} autoCreate @hide
  7193. */
  7194. /**
  7195. * @cfg {String} inputType @hide
  7196. */
  7197. /**
  7198. * @cfg {String} invalidClass @hide
  7199. */
  7200. /**
  7201. * @cfg {String} invalidText @hide
  7202. */
  7203. /**
  7204. * @cfg {String} msgFx @hide
  7205. */
  7206. /**
  7207. * @cfg {String} validateOnBlur @hide
  7208. */
  7209. /**
  7210. * @cfg {Boolean} allowDomMove @hide
  7211. */
  7212. /**
  7213. * @cfg {String} applyTo @hide
  7214. */
  7215. /**
  7216. * @cfg {String} autoHeight @hide
  7217. */
  7218. /**
  7219. * @cfg {String} autoWidth @hide
  7220. */
  7221. /**
  7222. * @cfg {String} cls @hide
  7223. */
  7224. /**
  7225. * @cfg {String} disabled @hide
  7226. */
  7227. /**
  7228. * @cfg {String} disabledClass @hide
  7229. */
  7230. /**
  7231. * @cfg {String} msgTarget @hide
  7232. */
  7233. /**
  7234. * @cfg {String} readOnly @hide
  7235. */
  7236. /**
  7237. * @cfg {String} style @hide
  7238. */
  7239. /**
  7240. * @cfg {String} validationDelay @hide
  7241. */
  7242. /**
  7243. * @cfg {String} validationEvent @hide
  7244. */
  7245. /**
  7246. * @cfg {String} tabIndex @hide
  7247. */
  7248. /**
  7249. * @property disabled
  7250. * @hide
  7251. */
  7252. /**
  7253. * @method applyToMarkup
  7254. * @hide
  7255. */
  7256. /**
  7257. * @method disable
  7258. * @hide
  7259. */
  7260. /**
  7261. * @method enable
  7262. * @hide
  7263. */
  7264. /**
  7265. * @method validate
  7266. * @hide
  7267. */
  7268. /**
  7269. * @event valid
  7270. * @hide
  7271. */
  7272. /**
  7273. * @method setDisabled
  7274. * @hide
  7275. */
  7276. /**
  7277. * @cfg keys
  7278. * @hide
  7279. */
  7280. });
  7281. Ext.reg('htmleditor', Ext.form.HtmlEditor);
  7282. /**
  7283. * @class Ext.form.TimeField
  7284. * @extends Ext.form.ComboBox
  7285. * Provides a time input field with a time dropdown and automatic time validation. Example usage:
  7286. * <pre><code>
  7287. new Ext.form.TimeField({
  7288. minValue: '9:00 AM',
  7289. maxValue: '6:00 PM',
  7290. increment: 30
  7291. });
  7292. </code></pre>
  7293. * @constructor
  7294. * Create a new TimeField
  7295. * @param {Object} config
  7296. * @xtype timefield
  7297. */
  7298. Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
  7299. /**
  7300. * @cfg {Date/String} minValue
  7301. * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string
  7302. * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
  7303. */
  7304. minValue : undefined,
  7305. /**
  7306. * @cfg {Date/String} maxValue
  7307. * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string
  7308. * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
  7309. */
  7310. maxValue : undefined,
  7311. /**
  7312. * @cfg {String} minText
  7313. * The error text to display when the date in the cell is before minValue (defaults to
  7314. * 'The time in this field must be equal to or after {0}').
  7315. */
  7316. minText : "The time in this field must be equal to or after {0}",
  7317. /**
  7318. * @cfg {String} maxText
  7319. * The error text to display when the time is after maxValue (defaults to
  7320. * 'The time in this field must be equal to or before {0}').
  7321. */
  7322. maxText : "The time in this field must be equal to or before {0}",
  7323. /**
  7324. * @cfg {String} invalidText
  7325. * The error text to display when the time in the field is invalid (defaults to
  7326. * '{value} is not a valid time').
  7327. */
  7328. invalidText : "{0} is not a valid time",
  7329. /**
  7330. * @cfg {String} format
  7331. * The default time format string which can be overriden for localization support. The format must be
  7332. * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
  7333. * format try 'H:i' instead.
  7334. */
  7335. format : "g:i A",
  7336. /**
  7337. * @cfg {String} altFormats
  7338. * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
  7339. * format (defaults to 'g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H|gi a|hi a|giA|hiA|gi A|hi A').
  7340. */
  7341. altFormats : "g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H|gi a|hi a|giA|hiA|gi A|hi A",
  7342. /**
  7343. * @cfg {Number} increment
  7344. * The number of minutes between each time value in the list (defaults to 15).
  7345. */
  7346. increment: 15,
  7347. // private override
  7348. mode: 'local',
  7349. // private override
  7350. triggerAction: 'all',
  7351. // private override
  7352. typeAhead: false,
  7353. // private - This is the date to use when generating time values in the absence of either minValue
  7354. // or maxValue. Using the current date causes DST issues on DST boundary dates, so this is an
  7355. // arbitrary "safe" date that can be any date aside from DST boundary dates.
  7356. initDate: '1/1/2008',
  7357. initDateFormat: 'j/n/Y',
  7358. // private
  7359. initComponent : function(){
  7360. if(Ext.isDefined(this.minValue)){
  7361. this.setMinValue(this.minValue, true);
  7362. }
  7363. if(Ext.isDefined(this.maxValue)){
  7364. this.setMaxValue(this.maxValue, true);
  7365. }
  7366. if(!this.store){
  7367. this.generateStore(true);
  7368. }
  7369. Ext.form.TimeField.superclass.initComponent.call(this);
  7370. },
  7371. /**
  7372. * Replaces any existing {@link #minValue} with the new time and refreshes the store.
  7373. * @param {Date/String} value The minimum time that can be selected
  7374. */
  7375. setMinValue: function(value, /* private */ initial){
  7376. this.setLimit(value, true, initial);
  7377. return this;
  7378. },
  7379. /**
  7380. * Replaces any existing {@link #maxValue} with the new time and refreshes the store.
  7381. * @param {Date/String} value The maximum time that can be selected
  7382. */
  7383. setMaxValue: function(value, /* private */ initial){
  7384. this.setLimit(value, false, initial);
  7385. return this;
  7386. },
  7387. // private
  7388. generateStore: function(initial){
  7389. var min = this.minValue || new Date(this.initDate).clearTime(),
  7390. max = this.maxValue || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1),
  7391. times = [];
  7392. while(min <= max){
  7393. times.push(min.dateFormat(this.format));
  7394. min = min.add('mi', this.increment);
  7395. }
  7396. this.bindStore(times, initial);
  7397. },
  7398. // private
  7399. setLimit: function(value, isMin, initial){
  7400. var d;
  7401. if(Ext.isString(value)){
  7402. d = this.parseDate(value);
  7403. }else if(Ext.isDate(value)){
  7404. d = value;
  7405. }
  7406. if(d){
  7407. var val = new Date(this.initDate).clearTime();
  7408. val.setHours(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
  7409. this[isMin ? 'minValue' : 'maxValue'] = val;
  7410. if(!initial){
  7411. this.generateStore();
  7412. }
  7413. }
  7414. },
  7415. // inherited docs
  7416. getValue : function(){
  7417. var v = Ext.form.TimeField.superclass.getValue.call(this);
  7418. return this.formatDate(this.parseDate(v)) || '';
  7419. },
  7420. // inherited docs
  7421. setValue : function(value){
  7422. return Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));
  7423. },
  7424. // private overrides
  7425. validateValue : Ext.form.DateField.prototype.validateValue,
  7426. formatDate : Ext.form.DateField.prototype.formatDate,
  7427. parseDate: function(value) {
  7428. if (!value || Ext.isDate(value)) {
  7429. return value;
  7430. }
  7431. var id = this.initDate + ' ',
  7432. idf = this.initDateFormat + ' ',
  7433. v = Date.parseDate(id + value, idf + this.format), // *** handle DST. note: this.format is a TIME-only format
  7434. af = this.altFormats;
  7435. if (!v && af) {
  7436. if (!this.altFormatsArray) {
  7437. this.altFormatsArray = af.split("|");
  7438. }
  7439. for (var i = 0, afa = this.altFormatsArray, len = afa.length; i < len && !v; i++) {
  7440. v = Date.parseDate(id + value, idf + afa[i]);
  7441. }
  7442. }
  7443. return v;
  7444. }
  7445. });
  7446. Ext.reg('timefield', Ext.form.TimeField);/**
  7447. * @class Ext.form.SliderField
  7448. * @extends Ext.form.Field
  7449. * Wraps a {@link Ext.slider.MultiSlider Slider} so it can be used as a form field.
  7450. * @constructor
  7451. * Creates a new SliderField
  7452. * @param {Object} config Configuration options. Note that you can pass in any slider configuration options, as well as
  7453. * as any field configuration options.
  7454. * @xtype sliderfield
  7455. */
  7456. Ext.form.SliderField = Ext.extend(Ext.form.Field, {
  7457. /**
  7458. * @cfg {Boolean} useTips
  7459. * True to use an Ext.slider.Tip to display tips for the value. Defaults to <tt>true</tt>.
  7460. */
  7461. useTips : true,
  7462. /**
  7463. * @cfg {Function} tipText
  7464. * A function used to display custom text for the slider tip. Defaults to <tt>null</tt>, which will
  7465. * use the default on the plugin.
  7466. */
  7467. tipText : null,
  7468. // private override
  7469. actionMode: 'wrap',
  7470. /**
  7471. * Initialize the component.
  7472. * @private
  7473. */
  7474. initComponent : function() {
  7475. var cfg = Ext.copyTo({
  7476. id: this.id + '-slider'
  7477. }, this.initialConfig, ['vertical', 'minValue', 'maxValue', 'decimalPrecision', 'keyIncrement', 'increment', 'clickToChange', 'animate']);
  7478. // only can use it if it exists.
  7479. if (this.useTips) {
  7480. var plug = this.tipText ? {getText: this.tipText} : {};
  7481. cfg.plugins = [new Ext.slider.Tip(plug)];
  7482. }
  7483. this.slider = new Ext.Slider(cfg);
  7484. Ext.form.SliderField.superclass.initComponent.call(this);
  7485. },
  7486. /**
  7487. * Set up the hidden field
  7488. * @param {Object} ct The container to render to.
  7489. * @param {Object} position The position in the container to render to.
  7490. * @private
  7491. */
  7492. onRender : function(ct, position){
  7493. this.autoCreate = {
  7494. id: this.id,
  7495. name: this.name,
  7496. type: 'hidden',
  7497. tag: 'input'
  7498. };
  7499. Ext.form.SliderField.superclass.onRender.call(this, ct, position);
  7500. this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
  7501. this.resizeEl = this.positionEl = this.wrap;
  7502. this.slider.render(this.wrap);
  7503. },
  7504. /**
  7505. * Ensure that the slider size is set automatically when the field resizes.
  7506. * @param {Object} w The width
  7507. * @param {Object} h The height
  7508. * @param {Object} aw The adjusted width
  7509. * @param {Object} ah The adjusted height
  7510. * @private
  7511. */
  7512. onResize : function(w, h, aw, ah){
  7513. Ext.form.SliderField.superclass.onResize.call(this, w, h, aw, ah);
  7514. this.slider.setSize(w, h);
  7515. },
  7516. /**
  7517. * Initialize any events for this class.
  7518. * @private
  7519. */
  7520. initEvents : function(){
  7521. Ext.form.SliderField.superclass.initEvents.call(this);
  7522. this.slider.on('change', this.onChange, this);
  7523. },
  7524. /**
  7525. * Utility method to set the value of the field when the slider changes.
  7526. * @param {Object} slider The slider object.
  7527. * @param {Object} v The new value.
  7528. * @private
  7529. */
  7530. onChange : function(slider, v){
  7531. this.setValue(v, undefined, true);
  7532. },
  7533. /**
  7534. * Enable the slider when the field is enabled.
  7535. * @private
  7536. */
  7537. onEnable : function(){
  7538. Ext.form.SliderField.superclass.onEnable.call(this);
  7539. this.slider.enable();
  7540. },
  7541. /**
  7542. * Disable the slider when the field is disabled.
  7543. * @private
  7544. */
  7545. onDisable : function(){
  7546. Ext.form.SliderField.superclass.onDisable.call(this);
  7547. this.slider.disable();
  7548. },
  7549. /**
  7550. * Ensure the slider is destroyed when the field is destroyed.
  7551. * @private
  7552. */
  7553. beforeDestroy : function(){
  7554. Ext.destroy(this.slider);
  7555. Ext.form.SliderField.superclass.beforeDestroy.call(this);
  7556. },
  7557. /**
  7558. * If a side icon is shown, do alignment to the slider
  7559. * @private
  7560. */
  7561. alignErrorIcon : function(){
  7562. this.errorIcon.alignTo(this.slider.el, 'tl-tr', [2, 0]);
  7563. },
  7564. /**
  7565. * Sets the minimum field value.
  7566. * @param {Number} v The new minimum value.
  7567. * @return {Ext.form.SliderField} this
  7568. */
  7569. setMinValue : function(v){
  7570. this.slider.setMinValue(v);
  7571. return this;
  7572. },
  7573. /**
  7574. * Sets the maximum field value.
  7575. * @param {Number} v The new maximum value.
  7576. * @return {Ext.form.SliderField} this
  7577. */
  7578. setMaxValue : function(v){
  7579. this.slider.setMaxValue(v);
  7580. return this;
  7581. },
  7582. /**
  7583. * Sets the value for this field.
  7584. * @param {Number} v The new value.
  7585. * @param {Boolean} animate (optional) Whether to animate the transition. If not specified, it will default to the animate config.
  7586. * @return {Ext.form.SliderField} this
  7587. */
  7588. setValue : function(v, animate, /* private */ silent){
  7589. // silent is used if the setValue method is invoked by the slider
  7590. // which means we don't need to set the value on the slider.
  7591. if(!silent){
  7592. this.slider.setValue(v, animate);
  7593. }
  7594. return Ext.form.SliderField.superclass.setValue.call(this, this.slider.getValue());
  7595. },
  7596. /**
  7597. * Gets the current value for this field.
  7598. * @return {Number} The current value.
  7599. */
  7600. getValue : function(){
  7601. return this.slider.getValue();
  7602. }
  7603. });
  7604. Ext.reg('sliderfield', Ext.form.SliderField);/**
  7605. * @class Ext.form.Label
  7606. * @extends Ext.BoxComponent
  7607. * Basic Label field.
  7608. * @constructor
  7609. * Creates a new Label
  7610. * @param {Ext.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
  7611. * element and its id used as the component id. If a string is passed, it is assumed to be the id of an existing element
  7612. * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
  7613. * @xtype label
  7614. */
  7615. Ext.form.Label = Ext.extend(Ext.BoxComponent, {
  7616. /**
  7617. * @cfg {String} text The plain text to display within the label (defaults to ''). If you need to include HTML
  7618. * tags within the label's innerHTML, use the {@link #html} config instead.
  7619. */
  7620. /**
  7621. * @cfg {String} forId The id of the input element to which this label will be bound via the standard HTML 'for'
  7622. * attribute. If not specified, the attribute will not be added to the label.
  7623. */
  7624. /**
  7625. * @cfg {String} html An HTML fragment that will be used as the label's innerHTML (defaults to '').
  7626. * Note that if {@link #text} is specified it will take precedence and this value will be ignored.
  7627. */
  7628. // private
  7629. onRender : function(ct, position){
  7630. if(!this.el){
  7631. this.el = document.createElement('label');
  7632. this.el.id = this.getId();
  7633. this.el.innerHTML = this.text ? Ext.util.Format.htmlEncode(this.text) : (this.html || '');
  7634. if(this.forId){
  7635. this.el.setAttribute('for', this.forId);
  7636. }
  7637. }
  7638. Ext.form.Label.superclass.onRender.call(this, ct, position);
  7639. },
  7640. /**
  7641. * Updates the label's innerHTML with the specified string.
  7642. * @param {String} text The new label text
  7643. * @param {Boolean} encode (optional) False to skip HTML-encoding the text when rendering it
  7644. * to the label (defaults to true which encodes the value). This might be useful if you want to include
  7645. * tags in the label's innerHTML rather than rendering them as string literals per the default logic.
  7646. * @return {Label} this
  7647. */
  7648. setText : function(t, encode){
  7649. var e = encode === false;
  7650. this[!e ? 'text' : 'html'] = t;
  7651. delete this[e ? 'text' : 'html'];
  7652. if(this.rendered){
  7653. this.el.dom.innerHTML = encode !== false ? Ext.util.Format.htmlEncode(t) : t;
  7654. }
  7655. return this;
  7656. }
  7657. });
  7658. Ext.reg('label', Ext.form.Label);/**
  7659. * @class Ext.form.Action
  7660. * <p>The subclasses of this class provide actions to perform upon {@link Ext.form.BasicForm Form}s.</p>
  7661. * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  7662. * the Form needs to perform an action such as submit or load. The Configuration options
  7663. * listed for this class are set through the Form's action methods: {@link Ext.form.BasicForm#submit submit},
  7664. * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}</p>
  7665. * <p>The instance of Action which performed the action is passed to the success
  7666. * and failure callbacks of the Form's action methods ({@link Ext.form.BasicForm#submit submit},
  7667. * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}),
  7668. * and to the {@link Ext.form.BasicForm#actioncomplete actioncomplete} and
  7669. * {@link Ext.form.BasicForm#actionfailed actionfailed} event handlers.</p>
  7670. */
  7671. Ext.form.Action = function(form, options){
  7672. this.form = form;
  7673. this.options = options || {};
  7674. };
  7675. /**
  7676. * Failure type returned when client side validation of the Form fails
  7677. * thus aborting a submit action. Client side validation is performed unless
  7678. * {@link #clientValidation} is explicitly set to <tt>false</tt>.
  7679. * @type {String}
  7680. * @static
  7681. */
  7682. Ext.form.Action.CLIENT_INVALID = 'client';
  7683. /**
  7684. * <p>Failure type returned when server side processing fails and the {@link #result}'s
  7685. * <tt style="font-weight:bold">success</tt> property is set to <tt>false</tt>.</p>
  7686. * <p>In the case of a form submission, field-specific error messages may be returned in the
  7687. * {@link #result}'s <tt style="font-weight:bold">errors</tt> property.</p>
  7688. * @type {String}
  7689. * @static
  7690. */
  7691. Ext.form.Action.SERVER_INVALID = 'server';
  7692. /**
  7693. * Failure type returned when a communication error happens when attempting
  7694. * to send a request to the remote server. The {@link #response} may be examined to
  7695. * provide further information.
  7696. * @type {String}
  7697. * @static
  7698. */
  7699. Ext.form.Action.CONNECT_FAILURE = 'connect';
  7700. /**
  7701. * Failure type returned when the response's <tt style="font-weight:bold">success</tt>
  7702. * property is set to <tt>false</tt>, or no field values are returned in the response's
  7703. * <tt style="font-weight:bold">data</tt> property.
  7704. * @type {String}
  7705. * @static
  7706. */
  7707. Ext.form.Action.LOAD_FAILURE = 'load';
  7708. Ext.form.Action.prototype = {
  7709. /**
  7710. * @cfg {String} url The URL that the Action is to invoke.
  7711. */
  7712. /**
  7713. * @cfg {Boolean} reset When set to <tt><b>true</b></tt>, causes the Form to be
  7714. * {@link Ext.form.BasicForm.reset reset} on Action success. If specified, this happens
  7715. * <b>before</b> the {@link #success} callback is called and before the Form's
  7716. * {@link Ext.form.BasicForm.actioncomplete actioncomplete} event fires.
  7717. */
  7718. /**
  7719. * @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the
  7720. * {@link Ext.form.BasicForm}'s method, or if that is not specified, the underlying DOM form's method.
  7721. */
  7722. /**
  7723. * @cfg {Mixed} params <p>Extra parameter values to pass. These are added to the Form's
  7724. * {@link Ext.form.BasicForm#baseParams} and passed to the specified URL along with the Form's
  7725. * input fields.</p>
  7726. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
  7727. */
  7728. /**
  7729. * @cfg {Number} timeout The number of seconds to wait for a server response before
  7730. * failing with the {@link #failureType} as {@link #Action.CONNECT_FAILURE}. If not specified,
  7731. * defaults to the configured <tt>{@link Ext.form.BasicForm#timeout timeout}</tt> of the
  7732. * {@link Ext.form.BasicForm form}.
  7733. */
  7734. /**
  7735. * @cfg {Function} success The function to call when a valid success return packet is recieved.
  7736. * The function is passed the following parameters:<ul class="mdetail-params">
  7737. * <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
  7738. * <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. The {@link #result}
  7739. * property of this object may be examined to perform custom postprocessing.</div></li>
  7740. * </ul>
  7741. */
  7742. /**
  7743. * @cfg {Function} failure The function to call when a failure packet was recieved, or when an
  7744. * error ocurred in the Ajax communication.
  7745. * The function is passed the following parameters:<ul class="mdetail-params">
  7746. * <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
  7747. * <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. If an Ajax
  7748. * error ocurred, the failure type will be in {@link #failureType}. The {@link #result}
  7749. * property of this object may be examined to perform custom postprocessing.</div></li>
  7750. * </ul>
  7751. */
  7752. /**
  7753. * @cfg {Object} scope The scope in which to call the callback functions (The <tt>this</tt> reference
  7754. * for the callback functions).
  7755. */
  7756. /**
  7757. * @cfg {String} waitMsg The message to be displayed by a call to {@link Ext.MessageBox#wait}
  7758. * during the time the action is being processed.
  7759. */
  7760. /**
  7761. * @cfg {String} waitTitle The title to be displayed by a call to {@link Ext.MessageBox#wait}
  7762. * during the time the action is being processed.
  7763. */
  7764. /**
  7765. * @cfg {Boolean} submitEmptyText If set to <tt>true</tt>, the emptyText value will be sent with the form
  7766. * when it is submitted. Defaults to <tt>true</tt>.
  7767. */
  7768. /**
  7769. * The type of action this Action instance performs.
  7770. * Currently only "submit" and "load" are supported.
  7771. * @type {String}
  7772. */
  7773. type : 'default',
  7774. /**
  7775. * The type of failure detected will be one of these: {@link #CLIENT_INVALID},
  7776. * {@link #SERVER_INVALID}, {@link #CONNECT_FAILURE}, or {@link #LOAD_FAILURE}. Usage:
  7777. * <pre><code>
  7778. var fp = new Ext.form.FormPanel({
  7779. ...
  7780. buttons: [{
  7781. text: 'Save',
  7782. formBind: true,
  7783. handler: function(){
  7784. if(fp.getForm().isValid()){
  7785. fp.getForm().submit({
  7786. url: 'form-submit.php',
  7787. waitMsg: 'Submitting your data...',
  7788. success: function(form, action){
  7789. // server responded with success = true
  7790. var result = action.{@link #result};
  7791. },
  7792. failure: function(form, action){
  7793. if (action.{@link #failureType} === Ext.form.Action.{@link #CONNECT_FAILURE}) {
  7794. Ext.Msg.alert('Error',
  7795. 'Status:'+action.{@link #response}.status+': '+
  7796. action.{@link #response}.statusText);
  7797. }
  7798. if (action.failureType === Ext.form.Action.{@link #SERVER_INVALID}){
  7799. // server responded with success = false
  7800. Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
  7801. }
  7802. }
  7803. });
  7804. }
  7805. }
  7806. },{
  7807. text: 'Reset',
  7808. handler: function(){
  7809. fp.getForm().reset();
  7810. }
  7811. }]
  7812. * </code></pre>
  7813. * @property failureType
  7814. * @type {String}
  7815. */
  7816. /**
  7817. * The XMLHttpRequest object used to perform the action.
  7818. * @property response
  7819. * @type {Object}
  7820. */
  7821. /**
  7822. * The decoded response object containing a boolean <tt style="font-weight:bold">success</tt> property and
  7823. * other, action-specific properties.
  7824. * @property result
  7825. * @type {Object}
  7826. */
  7827. // interface method
  7828. run : function(options){
  7829. },
  7830. // interface method
  7831. success : function(response){
  7832. },
  7833. // interface method
  7834. handleResponse : function(response){
  7835. },
  7836. // default connection failure
  7837. failure : function(response){
  7838. this.response = response;
  7839. this.failureType = Ext.form.Action.CONNECT_FAILURE;
  7840. this.form.afterAction(this, false);
  7841. },
  7842. // private
  7843. // shared code among all Actions to validate that there was a response
  7844. // with either responseText or responseXml
  7845. processResponse : function(response){
  7846. this.response = response;
  7847. if(!response.responseText && !response.responseXML){
  7848. return true;
  7849. }
  7850. this.result = this.handleResponse(response);
  7851. return this.result;
  7852. },
  7853. decodeResponse: function(response) {
  7854. try {
  7855. return Ext.decode(response.responseText);
  7856. } catch(e) {
  7857. return false;
  7858. }
  7859. },
  7860. // utility functions used internally
  7861. getUrl : function(appendParams){
  7862. var url = this.options.url || this.form.url || this.form.el.dom.action;
  7863. if(appendParams){
  7864. var p = this.getParams();
  7865. if(p){
  7866. url = Ext.urlAppend(url, p);
  7867. }
  7868. }
  7869. return url;
  7870. },
  7871. // private
  7872. getMethod : function(){
  7873. return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
  7874. },
  7875. // private
  7876. getParams : function(){
  7877. var bp = this.form.baseParams;
  7878. var p = this.options.params;
  7879. if(p){
  7880. if(typeof p == "object"){
  7881. p = Ext.urlEncode(Ext.applyIf(p, bp));
  7882. }else if(typeof p == 'string' && bp){
  7883. p += '&' + Ext.urlEncode(bp);
  7884. }
  7885. }else if(bp){
  7886. p = Ext.urlEncode(bp);
  7887. }
  7888. return p;
  7889. },
  7890. // private
  7891. createCallback : function(opts){
  7892. var opts = opts || {};
  7893. return {
  7894. success: this.success,
  7895. failure: this.failure,
  7896. scope: this,
  7897. timeout: (opts.timeout*1000) || (this.form.timeout*1000),
  7898. upload: this.form.fileUpload ? this.success : undefined
  7899. };
  7900. }
  7901. };
  7902. /**
  7903. * @class Ext.form.Action.Submit
  7904. * @extends Ext.form.Action
  7905. * <p>A class which handles submission of data from {@link Ext.form.BasicForm Form}s
  7906. * and processes the returned response.</p>
  7907. * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  7908. * {@link Ext.form.BasicForm#submit submit}ting.</p>
  7909. * <p><u><b>Response Packet Criteria</b></u></p>
  7910. * <p>A response packet may contain:
  7911. * <div class="mdetail-params"><ul>
  7912. * <li><b><code>success</code></b> property : Boolean
  7913. * <div class="sub-desc">The <code>success</code> property is required.</div></li>
  7914. * <li><b><code>errors</code></b> property : Object
  7915. * <div class="sub-desc"><div class="sub-desc">The <code>errors</code> property,
  7916. * which is optional, contains error messages for invalid fields.</div></li>
  7917. * </ul></div>
  7918. * <p><u><b>JSON Packets</b></u></p>
  7919. * <p>By default, response packets are assumed to be JSON, so a typical response
  7920. * packet may look like this:</p><pre><code>
  7921. {
  7922. success: false,
  7923. errors: {
  7924. clientCode: "Client not found",
  7925. portOfLoading: "This field must not be null"
  7926. }
  7927. }</code></pre>
  7928. * <p>Other data may be placed into the response for processing by the {@link Ext.form.BasicForm}'s callback
  7929. * or event handler methods. The object decoded from this JSON is available in the
  7930. * {@link Ext.form.Action#result result} property.</p>
  7931. * <p>Alternatively, if an {@link #errorReader} is specified as an {@link Ext.data.XmlReader XmlReader}:</p><pre><code>
  7932. errorReader: new Ext.data.XmlReader({
  7933. record : 'field',
  7934. success: '@success'
  7935. }, [
  7936. 'id', 'msg'
  7937. ]
  7938. )
  7939. </code></pre>
  7940. * <p>then the results may be sent back in XML format:</p><pre><code>
  7941. &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  7942. &lt;message success="false"&gt;
  7943. &lt;errors&gt;
  7944. &lt;field&gt;
  7945. &lt;id&gt;clientCode&lt;/id&gt;
  7946. &lt;msg&gt;&lt;![CDATA[Code not found. &lt;br /&gt;&lt;i&gt;This is a test validation message from the server &lt;/i&gt;]]&gt;&lt;/msg&gt;
  7947. &lt;/field&gt;
  7948. &lt;field&gt;
  7949. &lt;id&gt;portOfLoading&lt;/id&gt;
  7950. &lt;msg&gt;&lt;![CDATA[Port not found. &lt;br /&gt;&lt;i&gt;This is a test validation message from the server &lt;/i&gt;]]&gt;&lt;/msg&gt;
  7951. &lt;/field&gt;
  7952. &lt;/errors&gt;
  7953. &lt;/message&gt;
  7954. </code></pre>
  7955. * <p>Other elements may be placed into the response XML for processing by the {@link Ext.form.BasicForm}'s callback
  7956. * or event handler methods. The XML document is available in the {@link #errorReader}'s {@link Ext.data.XmlReader#xmlData xmlData} property.</p>
  7957. */
  7958. Ext.form.Action.Submit = function(form, options){
  7959. Ext.form.Action.Submit.superclass.constructor.call(this, form, options);
  7960. };
  7961. Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
  7962. /**
  7963. * @cfg {Ext.data.DataReader} errorReader <p><b>Optional. JSON is interpreted with
  7964. * no need for an errorReader.</b></p>
  7965. * <p>A Reader which reads a single record from the returned data. The DataReader's
  7966. * <b>success</b> property specifies how submission success is determined. The Record's
  7967. * data provides the error messages to apply to any invalid form Fields.</p>
  7968. */
  7969. /**
  7970. * @cfg {boolean} clientValidation Determines whether a Form's fields are validated
  7971. * in a final call to {@link Ext.form.BasicForm#isValid isValid} prior to submission.
  7972. * Pass <tt>false</tt> in the Form's submit options to prevent this. If not defined, pre-submission field validation
  7973. * is performed.
  7974. */
  7975. type : 'submit',
  7976. // private
  7977. run : function(){
  7978. var o = this.options,
  7979. method = this.getMethod(),
  7980. isGet = method == 'GET';
  7981. if(o.clientValidation === false || this.form.isValid()){
  7982. if (o.submitEmptyText === false) {
  7983. var fields = this.form.items,
  7984. emptyFields = [],
  7985. setupEmptyFields = function(f){
  7986. if (f.el.getValue() == f.emptyText) {
  7987. emptyFields.push(f);
  7988. f.el.dom.value = "";
  7989. }
  7990. if(f.isComposite && f.rendered){
  7991. f.items.each(setupEmptyFields);
  7992. }
  7993. };
  7994. fields.each(setupEmptyFields);
  7995. }
  7996. Ext.Ajax.request(Ext.apply(this.createCallback(o), {
  7997. form:this.form.el.dom,
  7998. url:this.getUrl(isGet),
  7999. method: method,
  8000. headers: o.headers,
  8001. params:!isGet ? this.getParams() : null,
  8002. isUpload: this.form.fileUpload
  8003. }));
  8004. if (o.submitEmptyText === false) {
  8005. Ext.each(emptyFields, function(f) {
  8006. if (f.applyEmptyText) {
  8007. f.applyEmptyText();
  8008. }
  8009. });
  8010. }
  8011. }else if (o.clientValidation !== false){ // client validation failed
  8012. this.failureType = Ext.form.Action.CLIENT_INVALID;
  8013. this.form.afterAction(this, false);
  8014. }
  8015. },
  8016. // private
  8017. success : function(response){
  8018. var result = this.processResponse(response);
  8019. if(result === true || result.success){
  8020. this.form.afterAction(this, true);
  8021. return;
  8022. }
  8023. if(result.errors){
  8024. this.form.markInvalid(result.errors);
  8025. }
  8026. this.failureType = Ext.form.Action.SERVER_INVALID;
  8027. this.form.afterAction(this, false);
  8028. },
  8029. // private
  8030. handleResponse : function(response){
  8031. if(this.form.errorReader){
  8032. var rs = this.form.errorReader.read(response);
  8033. var errors = [];
  8034. if(rs.records){
  8035. for(var i = 0, len = rs.records.length; i < len; i++) {
  8036. var r = rs.records[i];
  8037. errors[i] = r.data;
  8038. }
  8039. }
  8040. if(errors.length < 1){
  8041. errors = null;
  8042. }
  8043. return {
  8044. success : rs.success,
  8045. errors : errors
  8046. };
  8047. }
  8048. return this.decodeResponse(response);
  8049. }
  8050. });
  8051. /**
  8052. * @class Ext.form.Action.Load
  8053. * @extends Ext.form.Action
  8054. * <p>A class which handles loading of data from a server into the Fields of an {@link Ext.form.BasicForm}.</p>
  8055. * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  8056. * {@link Ext.form.BasicForm#load load}ing.</p>
  8057. * <p><u><b>Response Packet Criteria</b></u></p>
  8058. * <p>A response packet <b>must</b> contain:
  8059. * <div class="mdetail-params"><ul>
  8060. * <li><b><code>success</code></b> property : Boolean</li>
  8061. * <li><b><code>data</code></b> property : Object</li>
  8062. * <div class="sub-desc">The <code>data</code> property contains the values of Fields to load.
  8063. * The individual value object for each Field is passed to the Field's
  8064. * {@link Ext.form.Field#setValue setValue} method.</div></li>
  8065. * </ul></div>
  8066. * <p><u><b>JSON Packets</b></u></p>
  8067. * <p>By default, response packets are assumed to be JSON, so for the following form load call:<pre><code>
  8068. var myFormPanel = new Ext.form.FormPanel({
  8069. title: 'Client and routing info',
  8070. items: [{
  8071. fieldLabel: 'Client',
  8072. name: 'clientName'
  8073. }, {
  8074. fieldLabel: 'Port of loading',
  8075. name: 'portOfLoading'
  8076. }, {
  8077. fieldLabel: 'Port of discharge',
  8078. name: 'portOfDischarge'
  8079. }]
  8080. });
  8081. myFormPanel.{@link Ext.form.FormPanel#getForm getForm}().{@link Ext.form.BasicForm#load load}({
  8082. url: '/getRoutingInfo.php',
  8083. params: {
  8084. consignmentRef: myConsignmentRef
  8085. },
  8086. failure: function(form, action) {
  8087. Ext.Msg.alert("Load failed", action.result.errorMessage);
  8088. }
  8089. });
  8090. </code></pre>
  8091. * a <b>success response</b> packet may look like this:</p><pre><code>
  8092. {
  8093. success: true,
  8094. data: {
  8095. clientName: "Fred. Olsen Lines",
  8096. portOfLoading: "FXT",
  8097. portOfDischarge: "OSL"
  8098. }
  8099. }</code></pre>
  8100. * while a <b>failure response</b> packet may look like this:</p><pre><code>
  8101. {
  8102. success: false,
  8103. errorMessage: "Consignment reference not found"
  8104. }</code></pre>
  8105. * <p>Other data may be placed into the response for processing the {@link Ext.form.BasicForm Form}'s
  8106. * callback or event handler methods. The object decoded from this JSON is available in the
  8107. * {@link Ext.form.Action#result result} property.</p>
  8108. */
  8109. Ext.form.Action.Load = function(form, options){
  8110. Ext.form.Action.Load.superclass.constructor.call(this, form, options);
  8111. this.reader = this.form.reader;
  8112. };
  8113. Ext.extend(Ext.form.Action.Load, Ext.form.Action, {
  8114. // private
  8115. type : 'load',
  8116. // private
  8117. run : function(){
  8118. Ext.Ajax.request(Ext.apply(
  8119. this.createCallback(this.options), {
  8120. method:this.getMethod(),
  8121. url:this.getUrl(false),
  8122. headers: this.options.headers,
  8123. params:this.getParams()
  8124. }));
  8125. },
  8126. // private
  8127. success : function(response){
  8128. var result = this.processResponse(response);
  8129. if(result === true || !result.success || !result.data){
  8130. this.failureType = Ext.form.Action.LOAD_FAILURE;
  8131. this.form.afterAction(this, false);
  8132. return;
  8133. }
  8134. this.form.clearInvalid();
  8135. this.form.setValues(result.data);
  8136. this.form.afterAction(this, true);
  8137. },
  8138. // private
  8139. handleResponse : function(response){
  8140. if(this.form.reader){
  8141. var rs = this.form.reader.read(response);
  8142. var data = rs.records && rs.records[0] ? rs.records[0].data : null;
  8143. return {
  8144. success : rs.success,
  8145. data : data
  8146. };
  8147. }
  8148. return this.decodeResponse(response);
  8149. }
  8150. });
  8151. /**
  8152. * @class Ext.form.Action.DirectLoad
  8153. * @extends Ext.form.Action.Load
  8154. * <p>Provides Ext.direct support for loading form data.</p>
  8155. * <p>This example illustrates usage of Ext.Direct to <b>load</b> a form through Ext.Direct.</p>
  8156. * <pre><code>
  8157. var myFormPanel = new Ext.form.FormPanel({
  8158. // configs for FormPanel
  8159. title: 'Basic Information',
  8160. renderTo: document.body,
  8161. width: 300, height: 160,
  8162. padding: 10,
  8163. // configs apply to child items
  8164. defaults: {anchor: '100%'},
  8165. defaultType: 'textfield',
  8166. items: [{
  8167. fieldLabel: 'Name',
  8168. name: 'name'
  8169. },{
  8170. fieldLabel: 'Email',
  8171. name: 'email'
  8172. },{
  8173. fieldLabel: 'Company',
  8174. name: 'company'
  8175. }],
  8176. // configs for BasicForm
  8177. api: {
  8178. // The server-side method to call for load() requests
  8179. load: Profile.getBasicInfo,
  8180. // The server-side must mark the submit handler as a 'formHandler'
  8181. submit: Profile.updateBasicInfo
  8182. },
  8183. // specify the order for the passed params
  8184. paramOrder: ['uid', 'foo']
  8185. });
  8186. // load the form
  8187. myFormPanel.getForm().load({
  8188. // pass 2 arguments to server side getBasicInfo method (len=2)
  8189. params: {
  8190. foo: 'bar',
  8191. uid: 34
  8192. }
  8193. });
  8194. * </code></pre>
  8195. * The data packet sent to the server will resemble something like:
  8196. * <pre><code>
  8197. [
  8198. {
  8199. "action":"Profile","method":"getBasicInfo","type":"rpc","tid":2,
  8200. "data":[34,"bar"] // note the order of the params
  8201. }
  8202. ]
  8203. * </code></pre>
  8204. * The form will process a data packet returned by the server that is similar
  8205. * to the following format:
  8206. * <pre><code>
  8207. [
  8208. {
  8209. "action":"Profile","method":"getBasicInfo","type":"rpc","tid":2,
  8210. "result":{
  8211. "success":true,
  8212. "data":{
  8213. "name":"Fred Flintstone",
  8214. "company":"Slate Rock and Gravel",
  8215. "email":"fred.flintstone@slaterg.com"
  8216. }
  8217. }
  8218. }
  8219. ]
  8220. * </code></pre>
  8221. */
  8222. Ext.form.Action.DirectLoad = Ext.extend(Ext.form.Action.Load, {
  8223. constructor: function(form, opts) {
  8224. Ext.form.Action.DirectLoad.superclass.constructor.call(this, form, opts);
  8225. },
  8226. type : 'directload',
  8227. run : function(){
  8228. var args = this.getParams();
  8229. args.push(this.success, this);
  8230. this.form.api.load.apply(window, args);
  8231. },
  8232. getParams : function() {
  8233. var buf = [], o = {};
  8234. var bp = this.form.baseParams;
  8235. var p = this.options.params;
  8236. Ext.apply(o, p, bp);
  8237. var paramOrder = this.form.paramOrder;
  8238. if(paramOrder){
  8239. for(var i = 0, len = paramOrder.length; i < len; i++){
  8240. buf.push(o[paramOrder[i]]);
  8241. }
  8242. }else if(this.form.paramsAsHash){
  8243. buf.push(o);
  8244. }
  8245. return buf;
  8246. },
  8247. // Direct actions have already been processed and therefore
  8248. // we can directly set the result; Direct Actions do not have
  8249. // a this.response property.
  8250. processResponse : function(result) {
  8251. this.result = result;
  8252. return result;
  8253. },
  8254. success : function(response, trans){
  8255. if(trans.type == Ext.Direct.exceptions.SERVER){
  8256. response = {};
  8257. }
  8258. Ext.form.Action.DirectLoad.superclass.success.call(this, response);
  8259. }
  8260. });
  8261. /**
  8262. * @class Ext.form.Action.DirectSubmit
  8263. * @extends Ext.form.Action.Submit
  8264. * <p>Provides Ext.direct support for submitting form data.</p>
  8265. * <p>This example illustrates usage of Ext.Direct to <b>submit</b> a form through Ext.Direct.</p>
  8266. * <pre><code>
  8267. var myFormPanel = new Ext.form.FormPanel({
  8268. // configs for FormPanel
  8269. title: 'Basic Information',
  8270. renderTo: document.body,
  8271. width: 300, height: 160,
  8272. padding: 10,
  8273. buttons:[{
  8274. text: 'Submit',
  8275. handler: function(){
  8276. myFormPanel.getForm().submit({
  8277. params: {
  8278. foo: 'bar',
  8279. uid: 34
  8280. }
  8281. });
  8282. }
  8283. }],
  8284. // configs apply to child items
  8285. defaults: {anchor: '100%'},
  8286. defaultType: 'textfield',
  8287. items: [{
  8288. fieldLabel: 'Name',
  8289. name: 'name'
  8290. },{
  8291. fieldLabel: 'Email',
  8292. name: 'email'
  8293. },{
  8294. fieldLabel: 'Company',
  8295. name: 'company'
  8296. }],
  8297. // configs for BasicForm
  8298. api: {
  8299. // The server-side method to call for load() requests
  8300. load: Profile.getBasicInfo,
  8301. // The server-side must mark the submit handler as a 'formHandler'
  8302. submit: Profile.updateBasicInfo
  8303. },
  8304. // specify the order for the passed params
  8305. paramOrder: ['uid', 'foo']
  8306. });
  8307. * </code></pre>
  8308. * The data packet sent to the server will resemble something like:
  8309. * <pre><code>
  8310. {
  8311. "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",
  8312. "result":{
  8313. "success":true,
  8314. "id":{
  8315. "extAction":"Profile","extMethod":"updateBasicInfo",
  8316. "extType":"rpc","extTID":"6","extUpload":"false",
  8317. "name":"Aaron Conran","email":"aaron@extjs.com","company":"Ext JS, LLC"
  8318. }
  8319. }
  8320. }
  8321. * </code></pre>
  8322. * The form will process a data packet returned by the server that is similar
  8323. * to the following:
  8324. * <pre><code>
  8325. // sample success packet (batched requests)
  8326. [
  8327. {
  8328. "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":3,
  8329. "result":{
  8330. "success":true
  8331. }
  8332. }
  8333. ]
  8334. // sample failure packet (one request)
  8335. {
  8336. "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",
  8337. "result":{
  8338. "errors":{
  8339. "email":"already taken"
  8340. },
  8341. "success":false,
  8342. "foo":"bar"
  8343. }
  8344. }
  8345. * </code></pre>
  8346. * Also see the discussion in {@link Ext.form.Action.DirectLoad}.
  8347. */
  8348. Ext.form.Action.DirectSubmit = Ext.extend(Ext.form.Action.Submit, {
  8349. constructor : function(form, opts) {
  8350. Ext.form.Action.DirectSubmit.superclass.constructor.call(this, form, opts);
  8351. },
  8352. type : 'directsubmit',
  8353. // override of Submit
  8354. run : function(){
  8355. var o = this.options;
  8356. if(o.clientValidation === false || this.form.isValid()){
  8357. // tag on any additional params to be posted in the
  8358. // form scope
  8359. this.success.params = this.getParams();
  8360. this.form.api.submit(this.form.el.dom, this.success, this);
  8361. }else if (o.clientValidation !== false){ // client validation failed
  8362. this.failureType = Ext.form.Action.CLIENT_INVALID;
  8363. this.form.afterAction(this, false);
  8364. }
  8365. },
  8366. getParams : function() {
  8367. var o = {};
  8368. var bp = this.form.baseParams;
  8369. var p = this.options.params;
  8370. Ext.apply(o, p, bp);
  8371. return o;
  8372. },
  8373. // Direct actions have already been processed and therefore
  8374. // we can directly set the result; Direct Actions do not have
  8375. // a this.response property.
  8376. processResponse : function(result) {
  8377. this.result = result;
  8378. return result;
  8379. },
  8380. success : function(response, trans){
  8381. if(trans.type == Ext.Direct.exceptions.SERVER){
  8382. response = {};
  8383. }
  8384. Ext.form.Action.DirectSubmit.superclass.success.call(this, response);
  8385. }
  8386. });
  8387. Ext.form.Action.ACTION_TYPES = {
  8388. 'load' : Ext.form.Action.Load,
  8389. 'submit' : Ext.form.Action.Submit,
  8390. 'directload' : Ext.form.Action.DirectLoad,
  8391. 'directsubmit' : Ext.form.Action.DirectSubmit
  8392. };
  8393. /**
  8394. * @class Ext.form.VTypes
  8395. * <p>This is a singleton object which contains a set of commonly used field validation functions.
  8396. * The validations provided are basic and intended to be easily customizable and extended.</p>
  8397. * <p>To add custom VTypes specify the <code>{@link Ext.form.TextField#vtype vtype}</code> validation
  8398. * test function, and optionally specify any corresponding error text to display and any keystroke
  8399. * filtering mask to apply. For example:</p>
  8400. * <pre><code>
  8401. // custom Vtype for vtype:'time'
  8402. var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
  8403. Ext.apply(Ext.form.VTypes, {
  8404. // vtype validation function
  8405. time: function(val, field) {
  8406. return timeTest.test(val);
  8407. },
  8408. // vtype Text property: The error text to display when the validation function returns false
  8409. timeText: 'Not a valid time. Must be in the format "12:34 PM".',
  8410. // vtype Mask property: The keystroke filter mask
  8411. timeMask: /[\d\s:amp]/i
  8412. });
  8413. * </code></pre>
  8414. * Another example:
  8415. * <pre><code>
  8416. // custom Vtype for vtype:'IPAddress'
  8417. Ext.apply(Ext.form.VTypes, {
  8418. IPAddress: function(v) {
  8419. return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
  8420. },
  8421. IPAddressText: 'Must be a numeric IP address',
  8422. IPAddressMask: /[\d\.]/i
  8423. });
  8424. * </code></pre>
  8425. * @singleton
  8426. */
  8427. Ext.form.VTypes = function(){
  8428. // closure these in so they are only created once.
  8429. var alpha = /^[a-zA-Z_]+$/,
  8430. alphanum = /^[a-zA-Z0-9_]+$/,
  8431. email = /^(\w+)([\-+.\'][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/,
  8432. url = /(((^https?)|(^ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  8433. // All these messages and functions are configurable
  8434. return {
  8435. /**
  8436. * The function used to validate email addresses. Note that this is a very basic validation -- complete
  8437. * validation per the email RFC specifications is very complex and beyond the scope of this class, although
  8438. * this function can be overridden if a more comprehensive validation scheme is desired. See the validation
  8439. * section of the <a href="http://en.wikipedia.org/wiki/E-mail_address">Wikipedia article on email addresses</a>
  8440. * for additional information. This implementation is intended to validate the following emails:<tt>
  8441. * 'barney@example.de', 'barney.rubble@example.com', 'barney-rubble@example.coop', 'barney+rubble@example.com'
  8442. * </tt>.
  8443. * @param {String} value The email address
  8444. * @return {Boolean} true if the RegExp test passed, and false if not.
  8445. */
  8446. 'email' : function(v){
  8447. return email.test(v);
  8448. },
  8449. /**
  8450. * The error text to display when the email validation function returns false. Defaults to:
  8451. * <tt>'This field should be an e-mail address in the format "user@example.com"'</tt>
  8452. * @type String
  8453. */
  8454. 'emailText' : 'This field should be an e-mail address in the format "user@example.com"',
  8455. /**
  8456. * The keystroke filter mask to be applied on email input. See the {@link #email} method for
  8457. * information about more complex email validation. Defaults to:
  8458. * <tt>/[a-z0-9_\.\-\+\'@]/i</tt>
  8459. * @type RegExp
  8460. */
  8461. 'emailMask' : /[a-z0-9_\.\-\+\'@]/i,
  8462. /**
  8463. * The function used to validate URLs
  8464. * @param {String} value The URL
  8465. * @return {Boolean} true if the RegExp test passed, and false if not.
  8466. */
  8467. 'url' : function(v){
  8468. return url.test(v);
  8469. },
  8470. /**
  8471. * The error text to display when the url validation function returns false. Defaults to:
  8472. * <tt>'This field should be a URL in the format "http:/'+'/www.example.com"'</tt>
  8473. * @type String
  8474. */
  8475. 'urlText' : 'This field should be a URL in the format "http:/'+'/www.example.com"',
  8476. /**
  8477. * The function used to validate alpha values
  8478. * @param {String} value The value
  8479. * @return {Boolean} true if the RegExp test passed, and false if not.
  8480. */
  8481. 'alpha' : function(v){
  8482. return alpha.test(v);
  8483. },
  8484. /**
  8485. * The error text to display when the alpha validation function returns false. Defaults to:
  8486. * <tt>'This field should only contain letters and _'</tt>
  8487. * @type String
  8488. */
  8489. 'alphaText' : 'This field should only contain letters and _',
  8490. /**
  8491. * The keystroke filter mask to be applied on alpha input. Defaults to:
  8492. * <tt>/[a-z_]/i</tt>
  8493. * @type RegExp
  8494. */
  8495. 'alphaMask' : /[a-z_]/i,
  8496. /**
  8497. * The function used to validate alphanumeric values
  8498. * @param {String} value The value
  8499. * @return {Boolean} true if the RegExp test passed, and false if not.
  8500. */
  8501. 'alphanum' : function(v){
  8502. return alphanum.test(v);
  8503. },
  8504. /**
  8505. * The error text to display when the alphanumeric validation function returns false. Defaults to:
  8506. * <tt>'This field should only contain letters, numbers and _'</tt>
  8507. * @type String
  8508. */
  8509. 'alphanumText' : 'This field should only contain letters, numbers and _',
  8510. /**
  8511. * The keystroke filter mask to be applied on alphanumeric input. Defaults to:
  8512. * <tt>/[a-z0-9_]/i</tt>
  8513. * @type RegExp
  8514. */
  8515. 'alphanumMask' : /[a-z0-9_]/i
  8516. };
  8517. }();