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.

9220 lines
313 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.form.Field
  9. * @extends Ext.BoxComponent
  10. * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
  11. * @constructor
  12. * Creates a new Field
  13. * @param {Object} config Configuration options
  14. * @xtype field
  15. */
  16. Ext.form.Field = Ext.extend(Ext.BoxComponent, {
  17. /**
  18. * <p>The label Element associated with this Field. <b>Only available after this Field has been rendered by a
  19. * {@link form Ext.layout.FormLayout} layout manager.</b></p>
  20. * @type Ext.Element
  21. * @property label
  22. */
  23. /**
  24. * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password, file (defaults
  25. * to 'text'). The types 'file' and 'password' must be used to render those field types currently -- there are
  26. * no separate Ext components for those. Note that if you use <tt>inputType:'file'</tt>, {@link #emptyText}
  27. * is not supported and should be avoided.
  28. */
  29. /**
  30. * @cfg {Number} tabIndex The tabIndex for this field. Note this only applies to fields that are rendered,
  31. * not those which are built via applyTo (defaults to undefined).
  32. */
  33. /**
  34. * @cfg {Mixed} value A value to initialize this field with (defaults to undefined).
  35. */
  36. /**
  37. * @cfg {String} name The field's HTML name attribute (defaults to '').
  38. * <b>Note</b>: this property must be set if this field is to be automatically included with
  39. * {@link Ext.form.BasicForm#submit form submit()}.
  40. */
  41. /**
  42. * @cfg {String} cls A custom CSS class to apply to the field's underlying element (defaults to '').
  43. */
  44. /**
  45. * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to 'x-form-invalid')
  46. */
  47. invalidClass : 'x-form-invalid',
  48. /**
  49. * @cfg {String} invalidText The error text to use when marking a field invalid and no message is provided
  50. * (defaults to 'The value in this field is invalid')
  51. */
  52. invalidText : 'The value in this field is invalid',
  53. /**
  54. * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to 'x-form-focus')
  55. */
  56. focusClass : 'x-form-focus',
  57. /**
  58. * @cfg {Boolean} preventMark
  59. * <tt>true</tt> to disable {@link #markInvalid marking the field invalid}.
  60. * Defaults to <tt>false</tt>.
  61. */
  62. /**
  63. * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
  64. automatic validation (defaults to 'keyup').
  65. */
  66. validationEvent : 'keyup',
  67. /**
  68. * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
  69. */
  70. validateOnBlur : true,
  71. /**
  72. * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation
  73. * is initiated (defaults to 250)
  74. */
  75. validationDelay : 250,
  76. /**
  77. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
  78. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  79. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  80. * <pre><code>{tag: 'input', type: 'text', size: '20', autocomplete: 'off'}</code></pre>
  81. */
  82. defaultAutoCreate : {tag: 'input', type: 'text', size: '20', autocomplete: 'off'},
  83. /**
  84. * @cfg {String} fieldClass The default CSS class for the field (defaults to 'x-form-field')
  85. */
  86. fieldClass : 'x-form-field',
  87. /**
  88. * @cfg {String} msgTarget <p>The location where the message text set through {@link #markInvalid} should display.
  89. * Must be one of the following values:</p>
  90. * <div class="mdetail-params"><ul>
  91. * <li><code>qtip</code> Display a quick tip containing the message when the user hovers over the field. This is the default.
  92. * <div class="subdesc"><b>{@link Ext.QuickTips#init Ext.QuickTips.init} must have been called for this setting to work.</b></div</li>
  93. * <li><code>title</code> Display the message in a default browser title attribute popup.</li>
  94. * <li><code>under</code> Add a block div beneath the field containing the error message.</li>
  95. * <li><code>side</code> Add an error icon to the right of the field, displaying the message in a popup on hover.</li>
  96. * <li><code>[element id]</code> Add the error message directly to the innerHTML of the specified element.</li>
  97. * </ul></div>
  98. */
  99. msgTarget : 'qtip',
  100. /**
  101. * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field
  102. * (defaults to 'normal').
  103. */
  104. msgFx : 'normal',
  105. /**
  106. * @cfg {Boolean} readOnly <tt>true</tt> to mark the field as readOnly in HTML
  107. * (defaults to <tt>false</tt>).
  108. * <br><p><b>Note</b>: this only sets the element's readOnly DOM attribute.
  109. * Setting <code>readOnly=true</code>, for example, will not disable triggering a
  110. * ComboBox or DateField; it gives you the option of forcing the user to choose
  111. * via the trigger without typing in the text box. To hide the trigger use
  112. * <code>{@link Ext.form.TriggerField#hideTrigger hideTrigger}</code>.</p>
  113. */
  114. readOnly : false,
  115. /**
  116. * @cfg {Boolean} disabled True to disable the field (defaults to false).
  117. * <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>,
  118. * disabled Fields will not be {@link Ext.form.BasicForm#submit submitted}.</p>
  119. */
  120. disabled : false,
  121. /**
  122. * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
  123. * Defaults to <tt>true</tt>.
  124. */
  125. submitValue: true,
  126. // private
  127. isFormField : true,
  128. // private
  129. msgDisplay: '',
  130. // private
  131. hasFocus : false,
  132. // private
  133. initComponent : function(){
  134. Ext.form.Field.superclass.initComponent.call(this);
  135. this.addEvents(
  136. /**
  137. * @event focus
  138. * Fires when this field receives input focus.
  139. * @param {Ext.form.Field} this
  140. */
  141. 'focus',
  142. /**
  143. * @event blur
  144. * Fires when this field loses input focus.
  145. * @param {Ext.form.Field} this
  146. */
  147. 'blur',
  148. /**
  149. * @event specialkey
  150. * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed.
  151. * To handle other keys see {@link Ext.Panel#keys} or {@link Ext.KeyMap}.
  152. * You can check {@link Ext.EventObject#getKey} to determine which key was pressed.
  153. * For example: <pre><code>
  154. var form = new Ext.form.FormPanel({
  155. ...
  156. items: [{
  157. fieldLabel: 'Field 1',
  158. name: 'field1',
  159. allowBlank: false
  160. },{
  161. fieldLabel: 'Field 2',
  162. name: 'field2',
  163. listeners: {
  164. specialkey: function(field, e){
  165. // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
  166. // e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
  167. if (e.{@link Ext.EventObject#getKey getKey()} == e.ENTER) {
  168. var form = field.ownerCt.getForm();
  169. form.submit();
  170. }
  171. }
  172. }
  173. }
  174. ],
  175. ...
  176. });
  177. * </code></pre>
  178. * @param {Ext.form.Field} this
  179. * @param {Ext.EventObject} e The event object
  180. */
  181. 'specialkey',
  182. /**
  183. * @event change
  184. * Fires just before the field blurs if the field value has changed.
  185. * @param {Ext.form.Field} this
  186. * @param {Mixed} newValue The new value
  187. * @param {Mixed} oldValue The original value
  188. */
  189. 'change',
  190. /**
  191. * @event invalid
  192. * Fires after the field has been marked as invalid.
  193. * @param {Ext.form.Field} this
  194. * @param {String} msg The validation message
  195. */
  196. 'invalid',
  197. /**
  198. * @event valid
  199. * Fires after the field has been validated with no errors.
  200. * @param {Ext.form.Field} this
  201. */
  202. 'valid'
  203. );
  204. },
  205. /**
  206. * Returns the {@link Ext.form.Field#name name} or {@link Ext.form.ComboBox#hiddenName hiddenName}
  207. * attribute of the field if available.
  208. * @return {String} name The field {@link Ext.form.Field#name name} or {@link Ext.form.ComboBox#hiddenName hiddenName}
  209. */
  210. getName : function(){
  211. return this.rendered && this.el.dom.name ? this.el.dom.name : this.name || this.id || '';
  212. },
  213. // private
  214. onRender : function(ct, position){
  215. if(!this.el){
  216. var cfg = this.getAutoCreate();
  217. if(!cfg.name){
  218. cfg.name = this.name || this.id;
  219. }
  220. if(this.inputType){
  221. cfg.type = this.inputType;
  222. }
  223. this.autoEl = cfg;
  224. }
  225. Ext.form.Field.superclass.onRender.call(this, ct, position);
  226. if(this.submitValue === false){
  227. this.el.dom.removeAttribute('name');
  228. }
  229. var type = this.el.dom.type;
  230. if(type){
  231. if(type == 'password'){
  232. type = 'text';
  233. }
  234. this.el.addClass('x-form-'+type);
  235. }
  236. if(this.readOnly){
  237. this.setReadOnly(true);
  238. }
  239. if(this.tabIndex !== undefined){
  240. this.el.dom.setAttribute('tabIndex', this.tabIndex);
  241. }
  242. this.el.addClass([this.fieldClass, this.cls]);
  243. },
  244. // private
  245. getItemCt : function(){
  246. return this.itemCt;
  247. },
  248. // private
  249. initValue : function(){
  250. if(this.value !== undefined){
  251. this.setValue(this.value);
  252. }else if(!Ext.isEmpty(this.el.dom.value) && this.el.dom.value != this.emptyText){
  253. this.setValue(this.el.dom.value);
  254. }
  255. /**
  256. * The original value of the field as configured in the {@link #value} configuration, or
  257. * as loaded by the last form load operation if the form's {@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  258. * setting is <code>true</code>.
  259. * @type mixed
  260. * @property originalValue
  261. */
  262. this.originalValue = this.getValue();
  263. },
  264. /**
  265. * <p>Returns true if the value of this Field has been changed from its original value.
  266. * Will return false if the field is disabled or has not been rendered yet.</p>
  267. * <p>Note that if the owning {@link Ext.form.BasicForm form} was configured with
  268. * {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  269. * then the <i>original value</i> is updated when the values are loaded by
  270. * {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#setValues setValues}.</p>
  271. * @return {Boolean} True if this field has been changed from its original value (and
  272. * is not disabled), false otherwise.
  273. */
  274. isDirty : function() {
  275. if(this.disabled || !this.rendered) {
  276. return false;
  277. }
  278. return String(this.getValue()) !== String(this.originalValue);
  279. },
  280. /**
  281. * Sets the read only state of this field.
  282. * @param {Boolean} readOnly Whether the field should be read only.
  283. */
  284. setReadOnly : function(readOnly){
  285. if(this.rendered){
  286. this.el.dom.readOnly = readOnly;
  287. }
  288. this.readOnly = readOnly;
  289. },
  290. // private
  291. afterRender : function(){
  292. Ext.form.Field.superclass.afterRender.call(this);
  293. this.initEvents();
  294. this.initValue();
  295. },
  296. // private
  297. fireKey : function(e){
  298. if(e.isSpecialKey()){
  299. this.fireEvent('specialkey', this, e);
  300. }
  301. },
  302. /**
  303. * Resets the current field value to the originally loaded value and clears any validation messages.
  304. * See {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  305. */
  306. reset : function(){
  307. this.setValue(this.originalValue);
  308. this.clearInvalid();
  309. },
  310. // private
  311. initEvents : function(){
  312. this.mon(this.el, Ext.EventManager.getKeyEvent(), this.fireKey, this);
  313. this.mon(this.el, 'focus', this.onFocus, this);
  314. // standardise buffer across all browsers + OS-es for consistent event order.
  315. // (the 10ms buffer for Editors fixes a weird FF/Win editor issue when changing OS window focus)
  316. this.mon(this.el, 'blur', this.onBlur, this, this.inEditor ? {buffer:10} : null);
  317. },
  318. // private
  319. preFocus: Ext.emptyFn,
  320. // private
  321. onFocus : function(){
  322. this.preFocus();
  323. if(this.focusClass){
  324. this.el.addClass(this.focusClass);
  325. }
  326. if(!this.hasFocus){
  327. this.hasFocus = true;
  328. /**
  329. * <p>The value that the Field had at the time it was last focused. This is the value that is passed
  330. * to the {@link #change} event which is fired if the value has been changed when the Field is blurred.</p>
  331. * <p><b>This will be undefined until the Field has been visited.</b> Compare {@link #originalValue}.</p>
  332. * @type mixed
  333. * @property startValue
  334. */
  335. this.startValue = this.getValue();
  336. this.fireEvent('focus', this);
  337. }
  338. },
  339. // private
  340. beforeBlur : Ext.emptyFn,
  341. // private
  342. onBlur : function(){
  343. this.beforeBlur();
  344. if(this.focusClass){
  345. this.el.removeClass(this.focusClass);
  346. }
  347. this.hasFocus = false;
  348. if(this.validationEvent !== false && (this.validateOnBlur || this.validationEvent == 'blur')){
  349. this.validate();
  350. }
  351. var v = this.getValue();
  352. if(String(v) !== String(this.startValue)){
  353. this.fireEvent('change', this, v, this.startValue);
  354. }
  355. this.fireEvent('blur', this);
  356. this.postBlur();
  357. },
  358. // private
  359. postBlur : Ext.emptyFn,
  360. /**
  361. * Returns whether or not the field value is currently valid by
  362. * {@link #validateValue validating} the {@link #processValue processed value}
  363. * of the field. <b>Note</b>: {@link #disabled} fields are ignored.
  364. * @param {Boolean} preventMark True to disable marking the field invalid
  365. * @return {Boolean} True if the value is valid, else false
  366. */
  367. isValid : function(preventMark){
  368. if(this.disabled){
  369. return true;
  370. }
  371. var restore = this.preventMark;
  372. this.preventMark = preventMark === true;
  373. var v = this.validateValue(this.processValue(this.getRawValue()));
  374. this.preventMark = restore;
  375. return v;
  376. },
  377. /**
  378. * Validates the field value
  379. * @return {Boolean} True if the value is valid, else false
  380. */
  381. validate : function(){
  382. if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
  383. this.clearInvalid();
  384. return true;
  385. }
  386. return false;
  387. },
  388. /**
  389. * This method should only be overridden if necessary to prepare raw values
  390. * for validation (see {@link #validate} and {@link #isValid}). This method
  391. * is expected to return the processed value for the field which will
  392. * be used for validation (see validateValue method).
  393. * @param {Mixed} value
  394. */
  395. processValue : function(value){
  396. return value;
  397. },
  398. /**
  399. * Uses getErrors to build an array of validation errors. If any errors are found, markInvalid is called
  400. * with the first and false is returned, otherwise true is returned. Previously, subclasses were invited
  401. * to provide an implementation of this to process validations - from 3.2 onwards getErrors should be
  402. * overridden instead.
  403. * @param {Mixed} The current value of the field
  404. * @return {Boolean} True if all validations passed, false if one or more failed
  405. */
  406. validateValue : function(value) {
  407. //currently, we only show 1 error at a time for a field, so just use the first one
  408. var error = this.getErrors(value)[0];
  409. if (error == undefined) {
  410. return true;
  411. } else {
  412. this.markInvalid(error);
  413. return false;
  414. }
  415. },
  416. /**
  417. * Runs this field's validators and returns an array of error messages for any validation failures.
  418. * This is called internally during validation and would not usually need to be used manually.
  419. * Each subclass should override or augment the return value to provide their own errors
  420. * @return {Array} All error messages for this field
  421. */
  422. getErrors: function() {
  423. return [];
  424. },
  425. /**
  426. * Gets the active error message for this field.
  427. * @return {String} Returns the active error message on the field, if there is no error, an empty string is returned.
  428. */
  429. getActiveError : function(){
  430. return this.activeError || '';
  431. },
  432. /**
  433. * <p>Display an error message associated with this field, using {@link #msgTarget} to determine how to
  434. * display the message and applying {@link #invalidClass} to the field's UI element.</p>
  435. * <p><b>Note</b>: this method does not cause the Field's {@link #validate} method to return <code>false</code>
  436. * if the value does <i>pass</i> validation. So simply marking a Field as invalid will not prevent
  437. * submission of forms submitted with the {@link Ext.form.Action.Submit#clientValidation} option set.</p>
  438. * {@link #isValid invalid}.
  439. * @param {String} msg (optional) The validation message (defaults to {@link #invalidText})
  440. */
  441. markInvalid : function(msg){
  442. //don't set the error icon if we're not rendered or marking is prevented
  443. if (this.rendered && !this.preventMark) {
  444. msg = msg || this.invalidText;
  445. var mt = this.getMessageHandler();
  446. if(mt){
  447. mt.mark(this, msg);
  448. }else if(this.msgTarget){
  449. this.el.addClass(this.invalidClass);
  450. var t = Ext.getDom(this.msgTarget);
  451. if(t){
  452. t.innerHTML = msg;
  453. t.style.display = this.msgDisplay;
  454. }
  455. }
  456. }
  457. this.setActiveError(msg);
  458. },
  459. /**
  460. * Clear any invalid styles/messages for this field
  461. */
  462. clearInvalid : function(){
  463. //don't remove the error icon if we're not rendered or marking is prevented
  464. if (this.rendered && !this.preventMark) {
  465. this.el.removeClass(this.invalidClass);
  466. var mt = this.getMessageHandler();
  467. if(mt){
  468. mt.clear(this);
  469. }else if(this.msgTarget){
  470. this.el.removeClass(this.invalidClass);
  471. var t = Ext.getDom(this.msgTarget);
  472. if(t){
  473. t.innerHTML = '';
  474. t.style.display = 'none';
  475. }
  476. }
  477. }
  478. this.unsetActiveError();
  479. },
  480. /**
  481. * Sets the current activeError to the given string. Fires the 'invalid' event.
  482. * This does not set up the error icon, only sets the message and fires the event. To show the error icon,
  483. * use markInvalid instead, which calls this method internally
  484. * @param {String} msg The error message
  485. * @param {Boolean} suppressEvent True to suppress the 'invalid' event from being fired
  486. */
  487. setActiveError: function(msg, suppressEvent) {
  488. this.activeError = msg;
  489. if (suppressEvent !== true) this.fireEvent('invalid', this, msg);
  490. },
  491. /**
  492. * Clears the activeError and fires the 'valid' event. This is called internally by clearInvalid and would not
  493. * usually need to be called manually
  494. * @param {Boolean} suppressEvent True to suppress the 'invalid' event from being fired
  495. */
  496. unsetActiveError: function(suppressEvent) {
  497. delete this.activeError;
  498. if (suppressEvent !== true) this.fireEvent('valid', this);
  499. },
  500. // private
  501. getMessageHandler : function(){
  502. return Ext.form.MessageTargets[this.msgTarget];
  503. },
  504. // private
  505. getErrorCt : function(){
  506. return this.el.findParent('.x-form-element', 5, true) || // use form element wrap if available
  507. this.el.findParent('.x-form-field-wrap', 5, true); // else direct field wrap
  508. },
  509. // Alignment for 'under' target
  510. alignErrorEl : function(){
  511. this.errorEl.setWidth(this.getErrorCt().getWidth(true) - 20);
  512. },
  513. // Alignment for 'side' target
  514. alignErrorIcon : function(){
  515. this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
  516. },
  517. /**
  518. * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
  519. * @return {Mixed} value The field value
  520. */
  521. getRawValue : function(){
  522. var v = this.rendered ? this.el.getValue() : Ext.value(this.value, '');
  523. if(v === this.emptyText){
  524. v = '';
  525. }
  526. return v;
  527. },
  528. /**
  529. * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
  530. * @return {Mixed} value The field value
  531. */
  532. getValue : function(){
  533. if(!this.rendered) {
  534. return this.value;
  535. }
  536. var v = this.el.getValue();
  537. if(v === this.emptyText || v === undefined){
  538. v = '';
  539. }
  540. return v;
  541. },
  542. /**
  543. * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
  544. * @param {Mixed} value The value to set
  545. * @return {Mixed} value The field value that is set
  546. */
  547. setRawValue : function(v){
  548. return this.rendered ? (this.el.dom.value = (Ext.isEmpty(v) ? '' : v)) : '';
  549. },
  550. /**
  551. * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
  552. * @param {Mixed} value The value to set
  553. * @return {Ext.form.Field} this
  554. */
  555. setValue : function(v){
  556. this.value = v;
  557. if(this.rendered){
  558. this.el.dom.value = (Ext.isEmpty(v) ? '' : v);
  559. this.validate();
  560. }
  561. return this;
  562. },
  563. // private, does not work for all fields
  564. append : function(v){
  565. this.setValue([this.getValue(), v].join(''));
  566. }
  567. /**
  568. * @cfg {Boolean} autoWidth @hide
  569. */
  570. /**
  571. * @cfg {Boolean} autoHeight @hide
  572. */
  573. /**
  574. * @cfg {String} autoEl @hide
  575. */
  576. });
  577. Ext.form.MessageTargets = {
  578. 'qtip' : {
  579. mark: function(field, msg){
  580. field.el.addClass(field.invalidClass);
  581. field.el.dom.qtip = msg;
  582. field.el.dom.qclass = 'x-form-invalid-tip';
  583. if(Ext.QuickTips){ // fix for floating editors interacting with DND
  584. Ext.QuickTips.enable();
  585. }
  586. },
  587. clear: function(field){
  588. field.el.removeClass(field.invalidClass);
  589. field.el.dom.qtip = '';
  590. }
  591. },
  592. 'title' : {
  593. mark: function(field, msg){
  594. field.el.addClass(field.invalidClass);
  595. field.el.dom.title = msg;
  596. },
  597. clear: function(field){
  598. field.el.dom.title = '';
  599. }
  600. },
  601. 'under' : {
  602. mark: function(field, msg){
  603. field.el.addClass(field.invalidClass);
  604. if(!field.errorEl){
  605. var elp = field.getErrorCt();
  606. if(!elp){ // field has no container el
  607. field.el.dom.title = msg;
  608. return;
  609. }
  610. field.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
  611. field.on('resize', field.alignErrorEl, field);
  612. field.on('destroy', function(){
  613. Ext.destroy(this.errorEl);
  614. }, field);
  615. }
  616. field.alignErrorEl();
  617. field.errorEl.update(msg);
  618. Ext.form.Field.msgFx[field.msgFx].show(field.errorEl, field);
  619. },
  620. clear: function(field){
  621. field.el.removeClass(field.invalidClass);
  622. if(field.errorEl){
  623. Ext.form.Field.msgFx[field.msgFx].hide(field.errorEl, field);
  624. }else{
  625. field.el.dom.title = '';
  626. }
  627. }
  628. },
  629. 'side' : {
  630. mark: function(field, msg){
  631. field.el.addClass(field.invalidClass);
  632. if(!field.errorIcon){
  633. var elp = field.getErrorCt();
  634. // field has no container el
  635. if(!elp){
  636. field.el.dom.title = msg;
  637. return;
  638. }
  639. field.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
  640. if (field.ownerCt) {
  641. field.ownerCt.on('afterlayout', field.alignErrorIcon, field);
  642. field.ownerCt.on('expand', field.alignErrorIcon, field);
  643. }
  644. field.on('resize', field.alignErrorIcon, field);
  645. field.on('destroy', function(){
  646. Ext.destroy(this.errorIcon);
  647. }, field);
  648. }
  649. field.alignErrorIcon();
  650. field.errorIcon.dom.qtip = msg;
  651. field.errorIcon.dom.qclass = 'x-form-invalid-tip';
  652. field.errorIcon.show();
  653. },
  654. clear: function(field){
  655. field.el.removeClass(field.invalidClass);
  656. if(field.errorIcon){
  657. field.errorIcon.dom.qtip = '';
  658. field.errorIcon.hide();
  659. }else{
  660. field.el.dom.title = '';
  661. }
  662. }
  663. }
  664. };
  665. // anything other than normal should be considered experimental
  666. Ext.form.Field.msgFx = {
  667. normal : {
  668. show: function(msgEl, f){
  669. msgEl.setDisplayed('block');
  670. },
  671. hide : function(msgEl, f){
  672. msgEl.setDisplayed(false).update('');
  673. }
  674. },
  675. slide : {
  676. show: function(msgEl, f){
  677. msgEl.slideIn('t', {stopFx:true});
  678. },
  679. hide : function(msgEl, f){
  680. msgEl.slideOut('t', {stopFx:true,useDisplay:true});
  681. }
  682. },
  683. slideRight : {
  684. show: function(msgEl, f){
  685. msgEl.fixDisplay();
  686. msgEl.alignTo(f.el, 'tl-tr');
  687. msgEl.slideIn('l', {stopFx:true});
  688. },
  689. hide : function(msgEl, f){
  690. msgEl.slideOut('l', {stopFx:true,useDisplay:true});
  691. }
  692. }
  693. };
  694. Ext.reg('field', Ext.form.Field);
  695. /**
  696. * @class Ext.form.TextField
  697. * @extends Ext.form.Field
  698. * <p>Basic text field. Can be used as a direct replacement for traditional text inputs,
  699. * or as the base class for more sophisticated input controls (like {@link Ext.form.TextArea}
  700. * and {@link Ext.form.ComboBox}).</p>
  701. * <p><b><u>Validation</u></b></p>
  702. * <p>The validation procedure is described in the documentation for {@link #validateValue}.</p>
  703. * <p><b><u>Alter Validation Behavior</u></b></p>
  704. * <p>Validation behavior for each field can be configured:</p>
  705. * <div class="mdetail-params"><ul>
  706. * <li><code>{@link Ext.form.TextField#invalidText invalidText}</code> : the default validation message to
  707. * show if any validation step above does not provide a message when invalid</li>
  708. * <li><code>{@link Ext.form.TextField#maskRe maskRe}</code> : filter out keystrokes before any validation occurs</li>
  709. * <li><code>{@link Ext.form.TextField#stripCharsRe stripCharsRe}</code> : filter characters after being typed in,
  710. * but before being validated</li>
  711. * <li><code>{@link Ext.form.Field#invalidClass invalidClass}</code> : alternate style when invalid</li>
  712. * <li><code>{@link Ext.form.Field#validateOnBlur validateOnBlur}</code>,
  713. * <code>{@link Ext.form.Field#validationDelay validationDelay}</code>, and
  714. * <code>{@link Ext.form.Field#validationEvent validationEvent}</code> : modify how/when validation is triggered</li>
  715. * </ul></div>
  716. *
  717. * @constructor Creates a new TextField
  718. * @param {Object} config Configuration options
  719. *
  720. * @xtype textfield
  721. */
  722. Ext.form.TextField = Ext.extend(Ext.form.Field, {
  723. /**
  724. * @cfg {String} vtypeText A custom error message to display in place of the default message provided
  725. * for the <b><code>{@link #vtype}</code></b> currently set for this field (defaults to <tt>''</tt>). <b>Note</b>:
  726. * only applies if <b><code>{@link #vtype}</code></b> is set, else ignored.
  727. */
  728. /**
  729. * @cfg {RegExp} stripCharsRe A JavaScript RegExp object used to strip unwanted content from the value
  730. * before validation (defaults to <tt>null</tt>).
  731. */
  732. /**
  733. * @cfg {Boolean} grow <tt>true</tt> if this field should automatically grow and shrink to its content
  734. * (defaults to <tt>false</tt>)
  735. */
  736. grow : false,
  737. /**
  738. * @cfg {Number} growMin The minimum width to allow when <code><b>{@link #grow}</b> = true</code> (defaults
  739. * to <tt>30</tt>)
  740. */
  741. growMin : 30,
  742. /**
  743. * @cfg {Number} growMax The maximum width to allow when <code><b>{@link #grow}</b> = true</code> (defaults
  744. * to <tt>800</tt>)
  745. */
  746. growMax : 800,
  747. /**
  748. * @cfg {String} vtype A validation type name as defined in {@link Ext.form.VTypes} (defaults to <tt>null</tt>)
  749. */
  750. vtype : null,
  751. /**
  752. * @cfg {RegExp} maskRe An input mask regular expression that will be used to filter keystrokes that do
  753. * not match (defaults to <tt>null</tt>)
  754. */
  755. maskRe : null,
  756. /**
  757. * @cfg {Boolean} disableKeyFilter Specify <tt>true</tt> to disable input keystroke filtering (defaults
  758. * to <tt>false</tt>)
  759. */
  760. disableKeyFilter : false,
  761. /**
  762. * @cfg {Boolean} allowBlank Specify <tt>false</tt> to validate that the value's length is > 0 (defaults to
  763. * <tt>true</tt>)
  764. */
  765. allowBlank : true,
  766. /**
  767. * @cfg {Number} minLength Minimum input field length required (defaults to <tt>0</tt>)
  768. */
  769. minLength : 0,
  770. /**
  771. * @cfg {Number} maxLength Maximum input field length allowed by validation (defaults to Number.MAX_VALUE).
  772. * This behavior is intended to provide instant feedback to the user by improving usability to allow pasting
  773. * and editing or overtyping and back tracking. To restrict the maximum number of characters that can be
  774. * entered into the field use <tt><b>{@link Ext.form.Field#autoCreate autoCreate}</b></tt> to add
  775. * any attributes you want to a field, for example:<pre><code>
  776. var myField = new Ext.form.NumberField({
  777. id: 'mobile',
  778. anchor:'90%',
  779. fieldLabel: 'Mobile',
  780. maxLength: 16, // for validation
  781. autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '10'}
  782. });
  783. </code></pre>
  784. */
  785. maxLength : Number.MAX_VALUE,
  786. /**
  787. * @cfg {String} minLengthText Error text to display if the <b><tt>{@link #minLength minimum length}</tt></b>
  788. * validation fails (defaults to <tt>'The minimum length for this field is {minLength}'</tt>)
  789. */
  790. minLengthText : 'The minimum length for this field is {0}',
  791. /**
  792. * @cfg {String} maxLengthText Error text to display if the <b><tt>{@link #maxLength maximum length}</tt></b>
  793. * validation fails (defaults to <tt>'The maximum length for this field is {maxLength}'</tt>)
  794. */
  795. maxLengthText : 'The maximum length for this field is {0}',
  796. /**
  797. * @cfg {Boolean} selectOnFocus <tt>true</tt> to automatically select any existing field text when the field
  798. * receives input focus (defaults to <tt>false</tt>)
  799. */
  800. selectOnFocus : false,
  801. /**
  802. * @cfg {String} blankText The error text to display if the <b><tt>{@link #allowBlank}</tt></b> validation
  803. * fails (defaults to <tt>'This field is required'</tt>)
  804. */
  805. blankText : 'This field is required',
  806. /**
  807. * @cfg {Function} validator
  808. * <p>A custom validation function to be called during field validation ({@link #validateValue})
  809. * (defaults to <tt>null</tt>). If specified, this function will be called first, allowing the
  810. * developer to override the default validation process.</p>
  811. * <br><p>This function will be passed the following Parameters:</p>
  812. * <div class="mdetail-params"><ul>
  813. * <li><code>value</code>: <i>Mixed</i>
  814. * <div class="sub-desc">The current field value</div></li>
  815. * </ul></div>
  816. * <br><p>This function is to Return:</p>
  817. * <div class="mdetail-params"><ul>
  818. * <li><code>true</code>: <i>Boolean</i>
  819. * <div class="sub-desc"><code>true</code> if the value is valid</div></li>
  820. * <li><code>msg</code>: <i>String</i>
  821. * <div class="sub-desc">An error message if the value is invalid</div></li>
  822. * </ul></div>
  823. */
  824. validator : null,
  825. /**
  826. * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation
  827. * (defaults to <tt>null</tt>). If the test fails, the field will be marked invalid using
  828. * <b><tt>{@link #regexText}</tt></b>.
  829. */
  830. regex : null,
  831. /**
  832. * @cfg {String} regexText The error text to display if <b><tt>{@link #regex}</tt></b> is used and the
  833. * test fails during validation (defaults to <tt>''</tt>)
  834. */
  835. regexText : '',
  836. /**
  837. * @cfg {String} emptyText The default text to place into an empty field (defaults to <tt>null</tt>).
  838. * <b>Note</b>: that this value will be submitted to the server if this field is enabled and configured
  839. * with a {@link #name}.
  840. */
  841. emptyText : null,
  842. /**
  843. * @cfg {String} emptyClass The CSS class to apply to an empty field to style the <b><tt>{@link #emptyText}</tt></b>
  844. * (defaults to <tt>'x-form-empty-field'</tt>). This class is automatically added and removed as needed
  845. * depending on the current field value.
  846. */
  847. emptyClass : 'x-form-empty-field',
  848. /**
  849. * @cfg {Boolean} enableKeyEvents <tt>true</tt> to enable the proxying of key events for the HTML input
  850. * field (defaults to <tt>false</tt>)
  851. */
  852. initComponent : function(){
  853. Ext.form.TextField.superclass.initComponent.call(this);
  854. this.addEvents(
  855. /**
  856. * @event autosize
  857. * Fires when the <tt><b>{@link #autoSize}</b></tt> function is triggered. The field may or
  858. * may not have actually changed size according to the default logic, but this event provides
  859. * a hook for the developer to apply additional logic at runtime to resize the field if needed.
  860. * @param {Ext.form.Field} this This text field
  861. * @param {Number} width The new field width
  862. */
  863. 'autosize',
  864. /**
  865. * @event keydown
  866. * Keydown input field event. This event only fires if <tt><b>{@link #enableKeyEvents}</b></tt>
  867. * is set to true.
  868. * @param {Ext.form.TextField} this This text field
  869. * @param {Ext.EventObject} e
  870. */
  871. 'keydown',
  872. /**
  873. * @event keyup
  874. * Keyup 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. 'keyup',
  880. /**
  881. * @event keypress
  882. * Keypress 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. 'keypress'
  888. );
  889. },
  890. // private
  891. initEvents : function(){
  892. Ext.form.TextField.superclass.initEvents.call(this);
  893. if(this.validationEvent == 'keyup'){
  894. this.validationTask = new Ext.util.DelayedTask(this.validate, this);
  895. this.mon(this.el, 'keyup', this.filterValidation, this);
  896. }
  897. else if(this.validationEvent !== false && this.validationEvent != 'blur'){
  898. this.mon(this.el, this.validationEvent, this.validate, this, {buffer: this.validationDelay});
  899. }
  900. if(this.selectOnFocus || this.emptyText){
  901. this.mon(this.el, 'mousedown', this.onMouseDown, this);
  902. if(this.emptyText){
  903. this.applyEmptyText();
  904. }
  905. }
  906. if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Ext.form.VTypes[this.vtype+'Mask']))){
  907. this.mon(this.el, 'keypress', this.filterKeys, this);
  908. }
  909. if(this.grow){
  910. this.mon(this.el, 'keyup', this.onKeyUpBuffered, this, {buffer: 50});
  911. this.mon(this.el, 'click', this.autoSize, this);
  912. }
  913. if(this.enableKeyEvents){
  914. this.mon(this.el, {
  915. scope: this,
  916. keyup: this.onKeyUp,
  917. keydown: this.onKeyDown,
  918. keypress: this.onKeyPress
  919. });
  920. }
  921. },
  922. onMouseDown: function(e){
  923. if(!this.hasFocus){
  924. this.mon(this.el, 'mouseup', Ext.emptyFn, this, { single: true, preventDefault: true });
  925. }
  926. },
  927. processValue : function(value){
  928. if(this.stripCharsRe){
  929. var newValue = value.replace(this.stripCharsRe, '');
  930. if(newValue !== value){
  931. this.setRawValue(newValue);
  932. return newValue;
  933. }
  934. }
  935. return value;
  936. },
  937. filterValidation : function(e){
  938. if(!e.isNavKeyPress()){
  939. this.validationTask.delay(this.validationDelay);
  940. }
  941. },
  942. //private
  943. onDisable: function(){
  944. Ext.form.TextField.superclass.onDisable.call(this);
  945. if(Ext.isIE){
  946. this.el.dom.unselectable = 'on';
  947. }
  948. },
  949. //private
  950. onEnable: function(){
  951. Ext.form.TextField.superclass.onEnable.call(this);
  952. if(Ext.isIE){
  953. this.el.dom.unselectable = '';
  954. }
  955. },
  956. // private
  957. onKeyUpBuffered : function(e){
  958. if(this.doAutoSize(e)){
  959. this.autoSize();
  960. }
  961. },
  962. // private
  963. doAutoSize : function(e){
  964. return !e.isNavKeyPress();
  965. },
  966. // private
  967. onKeyUp : function(e){
  968. this.fireEvent('keyup', this, e);
  969. },
  970. // private
  971. onKeyDown : function(e){
  972. this.fireEvent('keydown', this, e);
  973. },
  974. // private
  975. onKeyPress : function(e){
  976. this.fireEvent('keypress', this, e);
  977. },
  978. /**
  979. * Resets the current field value to the originally-loaded value and clears any validation messages.
  980. * Also adds <tt><b>{@link #emptyText}</b></tt> and <tt><b>{@link #emptyClass}</b></tt> if the
  981. * original value was blank.
  982. */
  983. reset : function(){
  984. Ext.form.TextField.superclass.reset.call(this);
  985. this.applyEmptyText();
  986. },
  987. applyEmptyText : function(){
  988. if(this.rendered && this.emptyText && this.getRawValue().length < 1 && !this.hasFocus){
  989. this.setRawValue(this.emptyText);
  990. this.el.addClass(this.emptyClass);
  991. }
  992. },
  993. // private
  994. preFocus : function(){
  995. var el = this.el,
  996. isEmpty;
  997. if(this.emptyText){
  998. if(el.dom.value == this.emptyText){
  999. this.setRawValue('');
  1000. isEmpty = true;
  1001. }
  1002. el.removeClass(this.emptyClass);
  1003. }
  1004. if(this.selectOnFocus || isEmpty){
  1005. el.dom.select();
  1006. }
  1007. },
  1008. // private
  1009. postBlur : function(){
  1010. this.applyEmptyText();
  1011. },
  1012. // private
  1013. filterKeys : function(e){
  1014. if(e.ctrlKey){
  1015. return;
  1016. }
  1017. var k = e.getKey();
  1018. if(Ext.isGecko && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
  1019. return;
  1020. }
  1021. var cc = String.fromCharCode(e.getCharCode());
  1022. if(!Ext.isGecko && e.isSpecialKey() && !cc){
  1023. return;
  1024. }
  1025. if(!this.maskRe.test(cc)){
  1026. e.stopEvent();
  1027. }
  1028. },
  1029. setValue : function(v){
  1030. if(this.emptyText && this.el && !Ext.isEmpty(v)){
  1031. this.el.removeClass(this.emptyClass);
  1032. }
  1033. Ext.form.TextField.superclass.setValue.apply(this, arguments);
  1034. this.applyEmptyText();
  1035. this.autoSize();
  1036. return this;
  1037. },
  1038. /**
  1039. * <p>Validates a value according to the field's validation rules and returns an array of errors
  1040. * for any failing validations. Validation rules are processed in the following order:</p>
  1041. * <div class="mdetail-params"><ul>
  1042. *
  1043. * <li><b>1. Field specific validator</b>
  1044. * <div class="sub-desc">
  1045. * <p>A validator offers a way to customize and reuse a validation specification.
  1046. * If a field is configured with a <code>{@link #validator}</code>
  1047. * function, it will be passed the current field value. The <code>{@link #validator}</code>
  1048. * function is expected to return either:
  1049. * <div class="mdetail-params"><ul>
  1050. * <li>Boolean <tt>true</tt> if the value is valid (validation continues).</li>
  1051. * <li>a String to represent the invalid message if invalid (validation halts).</li>
  1052. * </ul></div>
  1053. * </div></li>
  1054. *
  1055. * <li><b>2. Basic Validation</b>
  1056. * <div class="sub-desc">
  1057. * <p>If the <code>{@link #validator}</code> has not halted validation,
  1058. * basic validation proceeds as follows:</p>
  1059. *
  1060. * <div class="mdetail-params"><ul>
  1061. *
  1062. * <li><code>{@link #allowBlank}</code> : (Invalid message =
  1063. * <code>{@link #emptyText}</code>)<div class="sub-desc">
  1064. * Depending on the configuration of <code>{@link #allowBlank}</code>, a
  1065. * blank field will cause validation to halt at this step and return
  1066. * Boolean true or false accordingly.
  1067. * </div></li>
  1068. *
  1069. * <li><code>{@link #minLength}</code> : (Invalid message =
  1070. * <code>{@link #minLengthText}</code>)<div class="sub-desc">
  1071. * If the passed value does not satisfy the <code>{@link #minLength}</code>
  1072. * specified, validation halts.
  1073. * </div></li>
  1074. *
  1075. * <li><code>{@link #maxLength}</code> : (Invalid message =
  1076. * <code>{@link #maxLengthText}</code>)<div class="sub-desc">
  1077. * If the passed value does not satisfy the <code>{@link #maxLength}</code>
  1078. * specified, validation halts.
  1079. * </div></li>
  1080. *
  1081. * </ul></div>
  1082. * </div></li>
  1083. *
  1084. * <li><b>3. Preconfigured Validation Types (VTypes)</b>
  1085. * <div class="sub-desc">
  1086. * <p>If none of the prior validation steps halts validation, a field
  1087. * configured with a <code>{@link #vtype}</code> will utilize the
  1088. * corresponding {@link Ext.form.VTypes VTypes} validation function.
  1089. * If invalid, either the field's <code>{@link #vtypeText}</code> or
  1090. * the VTypes vtype Text property will be used for the invalid message.
  1091. * Keystrokes on the field will be filtered according to the VTypes
  1092. * vtype Mask property.</p>
  1093. * </div></li>
  1094. *
  1095. * <li><b>4. Field specific regex test</b>
  1096. * <div class="sub-desc">
  1097. * <p>If none of the prior validation steps halts validation, a field's
  1098. * configured <code>{@link #regex}</code> test will be processed.
  1099. * The invalid message for this test is configured with
  1100. * <code>{@link #regexText}</code>.</p>
  1101. * </div></li>
  1102. *
  1103. * @param {Mixed} value The value to validate. The processed raw value will be used if nothing is passed
  1104. * @return {Array} Array of any validation errors
  1105. */
  1106. getErrors: function(value) {
  1107. var errors = Ext.form.TextField.superclass.getErrors.apply(this, arguments);
  1108. value = Ext.isDefined(value) ? value : this.processValue(this.getRawValue());
  1109. if (Ext.isFunction(this.validator)) {
  1110. var msg = this.validator(value);
  1111. if (msg !== true) {
  1112. errors.push(msg);
  1113. }
  1114. }
  1115. if (value.length < 1 || value === this.emptyText) {
  1116. if (this.allowBlank) {
  1117. //if value is blank and allowBlank is true, there cannot be any additional errors
  1118. return errors;
  1119. } else {
  1120. errors.push(this.blankText);
  1121. }
  1122. }
  1123. if (!this.allowBlank && (value.length < 1 || value === this.emptyText)) { // if it's blank
  1124. errors.push(this.blankText);
  1125. }
  1126. if (value.length < this.minLength) {
  1127. errors.push(String.format(this.minLengthText, this.minLength));
  1128. }
  1129. if (value.length > this.maxLength) {
  1130. errors.push(String.format(this.maxLengthText, this.maxLength));
  1131. }
  1132. if (this.vtype) {
  1133. var vt = Ext.form.VTypes;
  1134. if(!vt[this.vtype](value, this)){
  1135. errors.push(this.vtypeText || vt[this.vtype +'Text']);
  1136. }
  1137. }
  1138. if (this.regex && !this.regex.test(value)) {
  1139. errors.push(this.regexText);
  1140. }
  1141. return errors;
  1142. },
  1143. /**
  1144. * Selects text in this field
  1145. * @param {Number} start (optional) The index where the selection should start (defaults to 0)
  1146. * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
  1147. */
  1148. selectText : function(start, end){
  1149. var v = this.getRawValue();
  1150. var doFocus = false;
  1151. if(v.length > 0){
  1152. start = start === undefined ? 0 : start;
  1153. end = end === undefined ? v.length : end;
  1154. var d = this.el.dom;
  1155. if(d.setSelectionRange){
  1156. d.setSelectionRange(start, end);
  1157. }else if(d.createTextRange){
  1158. var range = d.createTextRange();
  1159. range.moveStart('character', start);
  1160. range.moveEnd('character', end-v.length);
  1161. range.select();
  1162. }
  1163. doFocus = Ext.isGecko || Ext.isOpera;
  1164. }else{
  1165. doFocus = true;
  1166. }
  1167. if(doFocus){
  1168. this.focus();
  1169. }
  1170. },
  1171. /**
  1172. * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
  1173. * This only takes effect if <tt><b>{@link #grow}</b> = true</tt>, and fires the {@link #autosize} event.
  1174. */
  1175. autoSize : function(){
  1176. if(!this.grow || !this.rendered){
  1177. return;
  1178. }
  1179. if(!this.metrics){
  1180. this.metrics = Ext.util.TextMetrics.createInstance(this.el);
  1181. }
  1182. var el = this.el;
  1183. var v = el.dom.value;
  1184. var d = document.createElement('div');
  1185. d.appendChild(document.createTextNode(v));
  1186. v = d.innerHTML;
  1187. Ext.removeNode(d);
  1188. d = null;
  1189. v += '&#160;';
  1190. var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
  1191. this.el.setWidth(w);
  1192. this.fireEvent('autosize', this, w);
  1193. },
  1194. onDestroy: function(){
  1195. if(this.validationTask){
  1196. this.validationTask.cancel();
  1197. this.validationTask = null;
  1198. }
  1199. Ext.form.TextField.superclass.onDestroy.call(this);
  1200. }
  1201. });
  1202. Ext.reg('textfield', Ext.form.TextField);
  1203. /**
  1204. * @class Ext.form.TriggerField
  1205. * @extends Ext.form.TextField
  1206. * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
  1207. * The trigger has no default action, so you must assign a function to implement the trigger click handler by
  1208. * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
  1209. * for which you can provide a custom implementation. For example:
  1210. * <pre><code>
  1211. var trigger = new Ext.form.TriggerField();
  1212. trigger.onTriggerClick = myTriggerFn;
  1213. trigger.applyToMarkup('my-field');
  1214. </code></pre>
  1215. *
  1216. * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
  1217. * {@link Ext.form.DateField} and {@link Ext.form.ComboBox} are perfect examples of this.
  1218. *
  1219. * @constructor
  1220. * Create a new TriggerField.
  1221. * @param {Object} config Configuration options (valid {@Ext.form.TextField} config options will also be applied
  1222. * to the base TextField)
  1223. * @xtype trigger
  1224. */
  1225. Ext.form.TriggerField = Ext.extend(Ext.form.TextField, {
  1226. /**
  1227. * @cfg {String} triggerClass
  1228. * An additional CSS class used to style the trigger button. The trigger will always get the
  1229. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  1230. */
  1231. /**
  1232. * @cfg {Mixed} triggerConfig
  1233. * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the
  1234. * trigger element for this Field. (Optional).</p>
  1235. * <p>Specify this when you need a customized element to act as the trigger button for a TriggerField.</p>
  1236. * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing, positioning
  1237. * and appearance of the trigger. Defaults to:</p>
  1238. * <pre><code>{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass}</code></pre>
  1239. */
  1240. /**
  1241. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
  1242. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  1243. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  1244. * <pre><code>{tag: "input", type: "text", size: "16", autocomplete: "off"}</code></pre>
  1245. */
  1246. defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
  1247. /**
  1248. * @cfg {Boolean} hideTrigger <tt>true</tt> to hide the trigger element and display only the base
  1249. * text field (defaults to <tt>false</tt>)
  1250. */
  1251. hideTrigger:false,
  1252. /**
  1253. * @cfg {Boolean} editable <tt>false</tt> to prevent the user from typing text directly into the field,
  1254. * the field will only respond to a click on the trigger to set the value. (defaults to <tt>true</tt>).
  1255. */
  1256. editable: true,
  1257. /**
  1258. * @cfg {Boolean} readOnly <tt>true</tt> to prevent the user from changing the field, and
  1259. * hides the trigger. Superceeds the editable and hideTrigger options if the value is true.
  1260. * (defaults to <tt>false</tt>)
  1261. */
  1262. readOnly: false,
  1263. /**
  1264. * @cfg {String} wrapFocusClass The class added to the to the wrap of the trigger element. Defaults to
  1265. * <tt>x-trigger-wrap-focus</tt>.
  1266. */
  1267. wrapFocusClass: 'x-trigger-wrap-focus',
  1268. /**
  1269. * @hide
  1270. * @method autoSize
  1271. */
  1272. autoSize: Ext.emptyFn,
  1273. // private
  1274. monitorTab : true,
  1275. // private
  1276. deferHeight : true,
  1277. // private
  1278. mimicing : false,
  1279. actionMode: 'wrap',
  1280. defaultTriggerWidth: 17,
  1281. // private
  1282. onResize : function(w, h){
  1283. Ext.form.TriggerField.superclass.onResize.call(this, w, h);
  1284. var tw = this.getTriggerWidth();
  1285. if(Ext.isNumber(w)){
  1286. this.el.setWidth(w - tw);
  1287. }
  1288. this.wrap.setWidth(this.el.getWidth() + tw);
  1289. },
  1290. getTriggerWidth: function(){
  1291. var tw = this.trigger.getWidth();
  1292. if(!this.hideTrigger && !this.readOnly && tw === 0){
  1293. tw = this.defaultTriggerWidth;
  1294. }
  1295. return tw;
  1296. },
  1297. // private
  1298. alignErrorIcon : function(){
  1299. if(this.wrap){
  1300. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  1301. }
  1302. },
  1303. // private
  1304. onRender : function(ct, position){
  1305. this.doc = Ext.isIE ? Ext.getBody() : Ext.getDoc();
  1306. Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
  1307. this.wrap = this.el.wrap({cls: 'x-form-field-wrap x-form-field-trigger-wrap'});
  1308. this.trigger = this.wrap.createChild(this.triggerConfig ||
  1309. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.triggerClass});
  1310. this.initTrigger();
  1311. if(!this.width){
  1312. this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
  1313. }
  1314. this.resizeEl = this.positionEl = this.wrap;
  1315. },
  1316. getWidth: function() {
  1317. return(this.el.getWidth() + this.trigger.getWidth());
  1318. },
  1319. updateEditState: function(){
  1320. if(this.rendered){
  1321. if (this.readOnly) {
  1322. this.el.dom.readOnly = true;
  1323. this.el.addClass('x-trigger-noedit');
  1324. this.mun(this.el, 'click', this.onTriggerClick, this);
  1325. this.trigger.setDisplayed(false);
  1326. } else {
  1327. if (!this.editable) {
  1328. this.el.dom.readOnly = true;
  1329. this.el.addClass('x-trigger-noedit');
  1330. this.mon(this.el, 'click', this.onTriggerClick, this);
  1331. } else {
  1332. this.el.dom.readOnly = false;
  1333. this.el.removeClass('x-trigger-noedit');
  1334. this.mun(this.el, 'click', this.onTriggerClick, this);
  1335. }
  1336. this.trigger.setDisplayed(!this.hideTrigger);
  1337. }
  1338. this.onResize(this.width || this.wrap.getWidth());
  1339. }
  1340. },
  1341. /**
  1342. * Changes the hidden status of the trigger.
  1343. * @param {Boolean} hideTrigger True to hide the trigger, false to show it.
  1344. */
  1345. setHideTrigger: function(hideTrigger){
  1346. if(hideTrigger != this.hideTrigger){
  1347. this.hideTrigger = hideTrigger;
  1348. this.updateEditState();
  1349. }
  1350. },
  1351. /**
  1352. * Allow or prevent the user from directly editing the field text. If false is passed,
  1353. * the user will only be able to modify the field using the trigger. Will also add
  1354. * a click event to the text field which will call the trigger. This method
  1355. * is the runtime equivalent of setting the {@link #editable} config option at config time.
  1356. * @param {Boolean} value True to allow the user to directly edit the field text.
  1357. */
  1358. setEditable: function(editable){
  1359. if(editable != this.editable){
  1360. this.editable = editable;
  1361. this.updateEditState();
  1362. }
  1363. },
  1364. /**
  1365. * Setting this to true will supersede settings {@link #editable} and {@link #hideTrigger}.
  1366. * Setting this to false will defer back to {@link #editable} and {@link #hideTrigger}. This method
  1367. * is the runtime equivalent of setting the {@link #readOnly} config option at config time.
  1368. * @param {Boolean} value True to prevent the user changing the field and explicitly
  1369. * hide the trigger.
  1370. */
  1371. setReadOnly: function(readOnly){
  1372. if(readOnly != this.readOnly){
  1373. this.readOnly = readOnly;
  1374. this.updateEditState();
  1375. }
  1376. },
  1377. afterRender : function(){
  1378. Ext.form.TriggerField.superclass.afterRender.call(this);
  1379. this.updateEditState();
  1380. },
  1381. // private
  1382. initTrigger : function(){
  1383. this.mon(this.trigger, 'click', this.onTriggerClick, this, {preventDefault:true});
  1384. this.trigger.addClassOnOver('x-form-trigger-over');
  1385. this.trigger.addClassOnClick('x-form-trigger-click');
  1386. },
  1387. // private
  1388. onDestroy : function(){
  1389. Ext.destroy(this.trigger, this.wrap);
  1390. if (this.mimicing){
  1391. this.doc.un('mousedown', this.mimicBlur, this);
  1392. }
  1393. delete this.doc;
  1394. Ext.form.TriggerField.superclass.onDestroy.call(this);
  1395. },
  1396. // private
  1397. onFocus : function(){
  1398. Ext.form.TriggerField.superclass.onFocus.call(this);
  1399. if(!this.mimicing){
  1400. this.wrap.addClass(this.wrapFocusClass);
  1401. this.mimicing = true;
  1402. this.doc.on('mousedown', this.mimicBlur, this, {delay: 10});
  1403. if(this.monitorTab){
  1404. this.on('specialkey', this.checkTab, this);
  1405. }
  1406. }
  1407. },
  1408. // private
  1409. checkTab : function(me, e){
  1410. if(e.getKey() == e.TAB){
  1411. this.triggerBlur();
  1412. }
  1413. },
  1414. // private
  1415. onBlur : Ext.emptyFn,
  1416. // private
  1417. mimicBlur : function(e){
  1418. if(!this.isDestroyed && !this.wrap.contains(e.target) && this.validateBlur(e)){
  1419. this.triggerBlur();
  1420. }
  1421. },
  1422. // private
  1423. triggerBlur : function(){
  1424. this.mimicing = false;
  1425. this.doc.un('mousedown', this.mimicBlur, this);
  1426. if(this.monitorTab && this.el){
  1427. this.un('specialkey', this.checkTab, this);
  1428. }
  1429. Ext.form.TriggerField.superclass.onBlur.call(this);
  1430. if(this.wrap){
  1431. this.wrap.removeClass(this.wrapFocusClass);
  1432. }
  1433. },
  1434. beforeBlur : Ext.emptyFn,
  1435. // private
  1436. // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
  1437. validateBlur : function(e){
  1438. return true;
  1439. },
  1440. /**
  1441. * The function that should handle the trigger's click event. This method does nothing by default
  1442. * until overridden by an implementing function. See Ext.form.ComboBox and Ext.form.DateField for
  1443. * sample implementations.
  1444. * @method
  1445. * @param {EventObject} e
  1446. */
  1447. onTriggerClick : Ext.emptyFn
  1448. /**
  1449. * @cfg {Boolean} grow @hide
  1450. */
  1451. /**
  1452. * @cfg {Number} growMin @hide
  1453. */
  1454. /**
  1455. * @cfg {Number} growMax @hide
  1456. */
  1457. });
  1458. /**
  1459. * @class Ext.form.TwinTriggerField
  1460. * @extends Ext.form.TriggerField
  1461. * TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
  1462. * to be extended by an implementing class. For an example of implementing this class, see the custom
  1463. * SearchField implementation here:
  1464. * <a href="http://extjs.com/deploy/ext/examples/form/custom.html">http://extjs.com/deploy/ext/examples/form/custom.html</a>
  1465. */
  1466. Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, {
  1467. /**
  1468. * @cfg {Mixed} triggerConfig
  1469. * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the trigger elements
  1470. * for this Field. (Optional).</p>
  1471. * <p>Specify this when you need a customized element to contain the two trigger elements for this Field.
  1472. * Each trigger element must be marked by the CSS class <tt>x-form-trigger</tt> (also see
  1473. * <tt>{@link #trigger1Class}</tt> and <tt>{@link #trigger2Class}</tt>).</p>
  1474. * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing,
  1475. * positioning and appearance of the triggers.</p>
  1476. */
  1477. /**
  1478. * @cfg {String} trigger1Class
  1479. * An additional CSS class used to style the trigger button. The trigger will always get the
  1480. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  1481. */
  1482. /**
  1483. * @cfg {String} trigger2Class
  1484. * An additional CSS class used to style the trigger button. The trigger will always get the
  1485. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  1486. */
  1487. initComponent : function(){
  1488. Ext.form.TwinTriggerField.superclass.initComponent.call(this);
  1489. this.triggerConfig = {
  1490. tag:'span', cls:'x-form-twin-triggers', cn:[
  1491. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.trigger1Class},
  1492. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.trigger2Class}
  1493. ]};
  1494. },
  1495. getTrigger : function(index){
  1496. return this.triggers[index];
  1497. },
  1498. afterRender: function(){
  1499. Ext.form.TwinTriggerField.superclass.afterRender.call(this);
  1500. var triggers = this.triggers,
  1501. i = 0,
  1502. len = triggers.length;
  1503. for(; i < len; ++i){
  1504. if(this['hideTrigger' + (i + 1)]){
  1505. triggers[i].hide();
  1506. }
  1507. }
  1508. },
  1509. initTrigger : function(){
  1510. var ts = this.trigger.select('.x-form-trigger', true),
  1511. triggerField = this;
  1512. ts.each(function(t, all, index){
  1513. var triggerIndex = 'Trigger'+(index+1);
  1514. t.hide = function(){
  1515. var w = triggerField.wrap.getWidth();
  1516. this.dom.style.display = 'none';
  1517. triggerField.el.setWidth(w-triggerField.trigger.getWidth());
  1518. triggerField['hidden' + triggerIndex] = true;
  1519. };
  1520. t.show = function(){
  1521. var w = triggerField.wrap.getWidth();
  1522. this.dom.style.display = '';
  1523. triggerField.el.setWidth(w-triggerField.trigger.getWidth());
  1524. triggerField['hidden' + triggerIndex] = false;
  1525. };
  1526. this.mon(t, 'click', this['on'+triggerIndex+'Click'], this, {preventDefault:true});
  1527. t.addClassOnOver('x-form-trigger-over');
  1528. t.addClassOnClick('x-form-trigger-click');
  1529. }, this);
  1530. this.triggers = ts.elements;
  1531. },
  1532. getTriggerWidth: function(){
  1533. var tw = 0;
  1534. Ext.each(this.triggers, function(t, index){
  1535. var triggerIndex = 'Trigger' + (index + 1),
  1536. w = t.getWidth();
  1537. if(w === 0 && !this['hidden' + triggerIndex]){
  1538. tw += this.defaultTriggerWidth;
  1539. }else{
  1540. tw += w;
  1541. }
  1542. }, this);
  1543. return tw;
  1544. },
  1545. // private
  1546. onDestroy : function() {
  1547. Ext.destroy(this.triggers);
  1548. Ext.form.TwinTriggerField.superclass.onDestroy.call(this);
  1549. },
  1550. /**
  1551. * The function that should handle the trigger's click event. This method does nothing by default
  1552. * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
  1553. * for additional information.
  1554. * @method
  1555. * @param {EventObject} e
  1556. */
  1557. onTrigger1Click : Ext.emptyFn,
  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. onTrigger2Click : Ext.emptyFn
  1566. });
  1567. Ext.reg('trigger', Ext.form.TriggerField);
  1568. /**
  1569. * @class Ext.form.TextArea
  1570. * @extends Ext.form.TextField
  1571. * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
  1572. * support for auto-sizing.
  1573. * @constructor
  1574. * Creates a new TextArea
  1575. * @param {Object} config Configuration options
  1576. * @xtype textarea
  1577. */
  1578. Ext.form.TextArea = Ext.extend(Ext.form.TextField, {
  1579. /**
  1580. * @cfg {Number} growMin The minimum height to allow when <tt>{@link Ext.form.TextField#grow grow}=true</tt>
  1581. * (defaults to <tt>60</tt>)
  1582. */
  1583. growMin : 60,
  1584. /**
  1585. * @cfg {Number} growMax The maximum height to allow when <tt>{@link Ext.form.TextField#grow grow}=true</tt>
  1586. * (defaults to <tt>1000</tt>)
  1587. */
  1588. growMax: 1000,
  1589. growAppend : '&#160;\n&#160;',
  1590. enterIsSpecial : false,
  1591. /**
  1592. * @cfg {Boolean} preventScrollbars <tt>true</tt> to prevent scrollbars from appearing regardless of how much text is
  1593. * in the field. This option is only relevant when {@link #grow} is <tt>true</tt>. Equivalent to setting overflow: hidden, defaults to
  1594. * <tt>false</tt>.
  1595. */
  1596. preventScrollbars: false,
  1597. /**
  1598. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
  1599. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  1600. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  1601. * <pre><code>{tag: "textarea", style: "width:100px;height:60px;", autocomplete: "off"}</code></pre>
  1602. */
  1603. // private
  1604. onRender : function(ct, position){
  1605. if(!this.el){
  1606. this.defaultAutoCreate = {
  1607. tag: "textarea",
  1608. style:"width:100px;height:60px;",
  1609. autocomplete: "off"
  1610. };
  1611. }
  1612. Ext.form.TextArea.superclass.onRender.call(this, ct, position);
  1613. if(this.grow){
  1614. this.textSizeEl = Ext.DomHelper.append(document.body, {
  1615. tag: "pre", cls: "x-form-grow-sizer"
  1616. });
  1617. if(this.preventScrollbars){
  1618. this.el.setStyle("overflow", "hidden");
  1619. }
  1620. this.el.setHeight(this.growMin);
  1621. }
  1622. },
  1623. onDestroy : function(){
  1624. Ext.removeNode(this.textSizeEl);
  1625. Ext.form.TextArea.superclass.onDestroy.call(this);
  1626. },
  1627. fireKey : function(e){
  1628. if(e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() != e.ENTER || e.hasModifier()))){
  1629. this.fireEvent("specialkey", this, e);
  1630. }
  1631. },
  1632. // private
  1633. doAutoSize : function(e){
  1634. return !e.isNavKeyPress() || e.getKey() == e.ENTER;
  1635. },
  1636. // inherit docs
  1637. filterValidation: function(e) {
  1638. if(!e.isNavKeyPress() || (!this.enterIsSpecial && e.keyCode == e.ENTER)){
  1639. this.validationTask.delay(this.validationDelay);
  1640. }
  1641. },
  1642. /**
  1643. * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
  1644. * This only takes effect if grow = true, and fires the {@link #autosize} event if the height changes.
  1645. */
  1646. autoSize: function(){
  1647. if(!this.grow || !this.textSizeEl){
  1648. return;
  1649. }
  1650. var el = this.el,
  1651. v = Ext.util.Format.htmlEncode(el.dom.value),
  1652. ts = this.textSizeEl,
  1653. h;
  1654. Ext.fly(ts).setWidth(this.el.getWidth());
  1655. if(v.length < 1){
  1656. v = "&#160;&#160;";
  1657. }else{
  1658. v += this.growAppend;
  1659. if(Ext.isIE){
  1660. v = v.replace(/\n/g, '&#160;<br />');
  1661. }
  1662. }
  1663. ts.innerHTML = v;
  1664. h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
  1665. if(h != this.lastHeight){
  1666. this.lastHeight = h;
  1667. this.el.setHeight(h);
  1668. this.fireEvent("autosize", this, h);
  1669. }
  1670. }
  1671. });
  1672. Ext.reg('textarea', Ext.form.TextArea);/**
  1673. * @class Ext.form.NumberField
  1674. * @extends Ext.form.TextField
  1675. * Numeric text field that provides automatic keystroke filtering and numeric validation.
  1676. * @constructor
  1677. * Creates a new NumberField
  1678. * @param {Object} config Configuration options
  1679. * @xtype numberfield
  1680. */
  1681. Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
  1682. /**
  1683. * @cfg {RegExp} stripCharsRe @hide
  1684. */
  1685. /**
  1686. * @cfg {RegExp} maskRe @hide
  1687. */
  1688. /**
  1689. * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
  1690. */
  1691. fieldClass: "x-form-field x-form-num-field",
  1692. /**
  1693. * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
  1694. */
  1695. allowDecimals : true,
  1696. /**
  1697. * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
  1698. */
  1699. decimalSeparator : ".",
  1700. /**
  1701. * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
  1702. */
  1703. decimalPrecision : 2,
  1704. /**
  1705. * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
  1706. */
  1707. allowNegative : true,
  1708. /**
  1709. * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
  1710. */
  1711. minValue : Number.NEGATIVE_INFINITY,
  1712. /**
  1713. * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
  1714. */
  1715. maxValue : Number.MAX_VALUE,
  1716. /**
  1717. * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
  1718. */
  1719. minText : "The minimum value for this field is {0}",
  1720. /**
  1721. * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
  1722. */
  1723. maxText : "The maximum value for this field is {0}",
  1724. /**
  1725. * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
  1726. * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
  1727. */
  1728. nanText : "{0} is not a valid number",
  1729. /**
  1730. * @cfg {String} baseChars The base set of characters to evaluate as valid numbers (defaults to '0123456789').
  1731. */
  1732. baseChars : "0123456789",
  1733. /**
  1734. * @cfg {Boolean} autoStripChars True to automatically strip not allowed characters from the field. Defaults to <tt>false</tt>
  1735. */
  1736. autoStripChars: false,
  1737. // private
  1738. initEvents : function() {
  1739. var allowed = this.baseChars + '';
  1740. if (this.allowDecimals) {
  1741. allowed += this.decimalSeparator;
  1742. }
  1743. if (this.allowNegative) {
  1744. allowed += '-';
  1745. }
  1746. allowed = Ext.escapeRe(allowed);
  1747. this.maskRe = new RegExp('[' + allowed + ']');
  1748. if (this.autoStripChars) {
  1749. this.stripCharsRe = new RegExp('[^' + allowed + ']', 'gi');
  1750. }
  1751. Ext.form.NumberField.superclass.initEvents.call(this);
  1752. },
  1753. /**
  1754. * Runs all of NumberFields validations and returns an array of any errors. Note that this first
  1755. * runs TextField's validations, so the returned array is an amalgamation of all field errors.
  1756. * The additional validations run test that the value is a number, and that it is within the
  1757. * configured min and max values.
  1758. * @param {Mixed} value The value to get errors for (defaults to the current field value)
  1759. * @return {Array} All validation errors for this field
  1760. */
  1761. getErrors: function(value) {
  1762. var errors = Ext.form.NumberField.superclass.getErrors.apply(this, arguments);
  1763. value = Ext.isDefined(value) ? value : this.processValue(this.getRawValue());
  1764. if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
  1765. return errors;
  1766. }
  1767. value = String(value).replace(this.decimalSeparator, ".");
  1768. if(isNaN(value)){
  1769. errors.push(String.format(this.nanText, value));
  1770. }
  1771. var num = this.parseValue(value);
  1772. if (num < this.minValue) {
  1773. errors.push(String.format(this.minText, this.minValue));
  1774. }
  1775. if (num > this.maxValue) {
  1776. errors.push(String.format(this.maxText, this.maxValue));
  1777. }
  1778. return errors;
  1779. },
  1780. getValue : function() {
  1781. return this.fixPrecision(this.parseValue(Ext.form.NumberField.superclass.getValue.call(this)));
  1782. },
  1783. setValue : function(v) {
  1784. v = this.fixPrecision(v);
  1785. v = Ext.isNumber(v) ? v : parseFloat(String(v).replace(this.decimalSeparator, "."));
  1786. v = isNaN(v) ? '' : String(v).replace(".", this.decimalSeparator);
  1787. return Ext.form.NumberField.superclass.setValue.call(this, v);
  1788. },
  1789. /**
  1790. * Replaces any existing {@link #minValue} with the new value.
  1791. * @param {Number} value The minimum value
  1792. */
  1793. setMinValue : function(value) {
  1794. this.minValue = Ext.num(value, Number.NEGATIVE_INFINITY);
  1795. },
  1796. /**
  1797. * Replaces any existing {@link #maxValue} with the new value.
  1798. * @param {Number} value The maximum value
  1799. */
  1800. setMaxValue : function(value) {
  1801. this.maxValue = Ext.num(value, Number.MAX_VALUE);
  1802. },
  1803. // private
  1804. parseValue : function(value) {
  1805. value = parseFloat(String(value).replace(this.decimalSeparator, "."));
  1806. return isNaN(value) ? '' : value;
  1807. },
  1808. /**
  1809. * @private
  1810. *
  1811. */
  1812. fixPrecision : function(value) {
  1813. var nan = isNaN(value);
  1814. if (!this.allowDecimals || this.decimalPrecision == -1 || nan || !value) {
  1815. return nan ? '' : value;
  1816. }
  1817. return parseFloat(parseFloat(value).toFixed(this.decimalPrecision));
  1818. },
  1819. beforeBlur : function() {
  1820. var v = this.parseValue(this.getRawValue());
  1821. if (!Ext.isEmpty(v)) {
  1822. this.setValue(v);
  1823. }
  1824. }
  1825. });
  1826. Ext.reg('numberfield', Ext.form.NumberField);
  1827. /**
  1828. * @class Ext.form.DateField
  1829. * @extends Ext.form.TriggerField
  1830. * Provides a date input field with a {@link Ext.DatePicker} dropdown and automatic date validation.
  1831. * @constructor
  1832. * Create a new DateField
  1833. * @param {Object} config
  1834. * @xtype datefield
  1835. */
  1836. Ext.form.DateField = Ext.extend(Ext.form.TriggerField, {
  1837. /**
  1838. * @cfg {String} format
  1839. * The default date format string which can be overriden for localization support. The format must be
  1840. * valid according to {@link Date#parseDate} (defaults to <tt>'m/d/Y'</tt>).
  1841. */
  1842. format : "m/d/Y",
  1843. /**
  1844. * @cfg {String} altFormats
  1845. * Multiple date formats separated by "<tt>|</tt>" to try when parsing a user input value and it
  1846. * does not match the defined format (defaults to
  1847. * <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>).
  1848. */
  1849. 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",
  1850. /**
  1851. * @cfg {String} disabledDaysText
  1852. * The tooltip to display when the date falls on a disabled day (defaults to <tt>'Disabled'</tt>)
  1853. */
  1854. disabledDaysText : "Disabled",
  1855. /**
  1856. * @cfg {String} disabledDatesText
  1857. * The tooltip text to display when the date falls on a disabled date (defaults to <tt>'Disabled'</tt>)
  1858. */
  1859. disabledDatesText : "Disabled",
  1860. /**
  1861. * @cfg {String} minText
  1862. * The error text to display when the date in the cell is before <tt>{@link #minValue}</tt> (defaults to
  1863. * <tt>'The date in this field must be after {minValue}'</tt>).
  1864. */
  1865. minText : "The date in this field must be equal to or after {0}",
  1866. /**
  1867. * @cfg {String} maxText
  1868. * The error text to display when the date in the cell is after <tt>{@link #maxValue}</tt> (defaults to
  1869. * <tt>'The date in this field must be before {maxValue}'</tt>).
  1870. */
  1871. maxText : "The date in this field must be equal to or before {0}",
  1872. /**
  1873. * @cfg {String} invalidText
  1874. * The error text to display when the date in the field is invalid (defaults to
  1875. * <tt>'{value} is not a valid date - it must be in the format {format}'</tt>).
  1876. */
  1877. invalidText : "{0} is not a valid date - it must be in the format {1}",
  1878. /**
  1879. * @cfg {String} triggerClass
  1880. * An additional CSS class used to style the trigger button. The trigger will always get the
  1881. * class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
  1882. * (defaults to <tt>'x-form-date-trigger'</tt> which displays a calendar icon).
  1883. */
  1884. triggerClass : 'x-form-date-trigger',
  1885. /**
  1886. * @cfg {Boolean} showToday
  1887. * <tt>false</tt> to hide the footer area of the DatePicker containing the Today button and disable
  1888. * the keyboard handler for spacebar that selects the current date (defaults to <tt>true</tt>).
  1889. */
  1890. showToday : true,
  1891. /**
  1892. * @cfg {Number} startDay
  1893. * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
  1894. */
  1895. startDay : 0,
  1896. /**
  1897. * @cfg {Date/String} minValue
  1898. * The minimum allowed date. Can be either a Javascript date object or a string date in a
  1899. * valid format (defaults to null).
  1900. */
  1901. /**
  1902. * @cfg {Date/String} maxValue
  1903. * The maximum allowed date. Can be either a Javascript date object or a string date in a
  1904. * valid format (defaults to null).
  1905. */
  1906. /**
  1907. * @cfg {Array} disabledDays
  1908. * An array of days to disable, 0 based (defaults to null). Some examples:<pre><code>
  1909. // disable Sunday and Saturday:
  1910. disabledDays: [0, 6]
  1911. // disable weekdays:
  1912. disabledDays: [1,2,3,4,5]
  1913. * </code></pre>
  1914. */
  1915. /**
  1916. * @cfg {Array} disabledDates
  1917. * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
  1918. * expression so they are very powerful. Some examples:<pre><code>
  1919. // disable these exact dates:
  1920. disabledDates: ["03/08/2003", "09/16/2003"]
  1921. // disable these days for every year:
  1922. disabledDates: ["03/08", "09/16"]
  1923. // only match the beginning (useful if you are using short years):
  1924. disabledDates: ["^03/08"]
  1925. // disable every day in March 2006:
  1926. disabledDates: ["03/../2006"]
  1927. // disable every day in every March:
  1928. disabledDates: ["^03"]
  1929. * </code></pre>
  1930. * Note that the format of the dates included in the array should exactly match the {@link #format} config.
  1931. * In order to support regular expressions, if you are using a {@link #format date format} that has "." in
  1932. * it, you will have to escape the dot when restricting dates. For example: <tt>["03\\.08\\.03"]</tt>.
  1933. */
  1934. /**
  1935. * @cfg {String/Object} autoCreate
  1936. * A {@link Ext.DomHelper DomHelper element specification object}, or <tt>true</tt> for the default element
  1937. * specification object:<pre><code>
  1938. * autoCreate: {tag: "input", type: "text", size: "10", autocomplete: "off"}
  1939. * </code></pre>
  1940. */
  1941. // private
  1942. defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
  1943. // in the absence of a time value, a default value of 12 noon will be used
  1944. // (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
  1945. initTime: '12', // 24 hour format
  1946. initTimeFormat: 'H',
  1947. // PUBLIC -- to be documented
  1948. safeParse : function(value, format) {
  1949. if (/[gGhH]/.test(format.replace(/(\\.)/g, ''))) {
  1950. // if parse format contains hour information, no DST adjustment is necessary
  1951. return Date.parseDate(value, format);
  1952. } else {
  1953. // set time to 12 noon, then clear the time
  1954. var parsedDate = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat);
  1955. if (parsedDate) {
  1956. return parsedDate.clearTime();
  1957. }
  1958. }
  1959. },
  1960. initComponent : function(){
  1961. Ext.form.DateField.superclass.initComponent.call(this);
  1962. this.addEvents(
  1963. /**
  1964. * @event select
  1965. * Fires when a date is selected via the date picker.
  1966. * @param {Ext.form.DateField} this
  1967. * @param {Date} date The date that was selected
  1968. */
  1969. 'select'
  1970. );
  1971. if(Ext.isString(this.minValue)){
  1972. this.minValue = this.parseDate(this.minValue);
  1973. }
  1974. if(Ext.isString(this.maxValue)){
  1975. this.maxValue = this.parseDate(this.maxValue);
  1976. }
  1977. this.disabledDatesRE = null;
  1978. this.initDisabledDays();
  1979. },
  1980. initEvents: function() {
  1981. Ext.form.DateField.superclass.initEvents.call(this);
  1982. this.keyNav = new Ext.KeyNav(this.el, {
  1983. "down": function(e) {
  1984. this.onTriggerClick();
  1985. },
  1986. scope: this,
  1987. forceKeyDown: true
  1988. });
  1989. },
  1990. // private
  1991. initDisabledDays : function(){
  1992. if(this.disabledDates){
  1993. var dd = this.disabledDates,
  1994. len = dd.length - 1,
  1995. re = "(?:";
  1996. Ext.each(dd, function(d, i){
  1997. re += Ext.isDate(d) ? '^' + Ext.escapeRe(d.dateFormat(this.format)) + '$' : dd[i];
  1998. if(i != len){
  1999. re += '|';
  2000. }
  2001. }, this);
  2002. this.disabledDatesRE = new RegExp(re + ')');
  2003. }
  2004. },
  2005. /**
  2006. * Replaces any existing disabled dates with new values and refreshes the DatePicker.
  2007. * @param {Array} disabledDates An array of date strings (see the <tt>{@link #disabledDates}</tt> config
  2008. * for details on supported values) used to disable a pattern of dates.
  2009. */
  2010. setDisabledDates : function(dd){
  2011. this.disabledDates = dd;
  2012. this.initDisabledDays();
  2013. if(this.menu){
  2014. this.menu.picker.setDisabledDates(this.disabledDatesRE);
  2015. }
  2016. },
  2017. /**
  2018. * Replaces any existing disabled days (by index, 0-6) with new values and refreshes the DatePicker.
  2019. * @param {Array} disabledDays An array of disabled day indexes. See the <tt>{@link #disabledDays}</tt>
  2020. * config for details on supported values.
  2021. */
  2022. setDisabledDays : function(dd){
  2023. this.disabledDays = dd;
  2024. if(this.menu){
  2025. this.menu.picker.setDisabledDays(dd);
  2026. }
  2027. },
  2028. /**
  2029. * Replaces any existing <tt>{@link #minValue}</tt> with the new value and refreshes the DatePicker.
  2030. * @param {Date} value The minimum date that can be selected
  2031. */
  2032. setMinValue : function(dt){
  2033. this.minValue = (Ext.isString(dt) ? this.parseDate(dt) : dt);
  2034. if(this.menu){
  2035. this.menu.picker.setMinDate(this.minValue);
  2036. }
  2037. },
  2038. /**
  2039. * Replaces any existing <tt>{@link #maxValue}</tt> with the new value and refreshes the DatePicker.
  2040. * @param {Date} value The maximum date that can be selected
  2041. */
  2042. setMaxValue : function(dt){
  2043. this.maxValue = (Ext.isString(dt) ? this.parseDate(dt) : dt);
  2044. if(this.menu){
  2045. this.menu.picker.setMaxDate(this.maxValue);
  2046. }
  2047. },
  2048. /**
  2049. * Runs all of NumberFields validations and returns an array of any errors. Note that this first
  2050. * runs TextField's validations, so the returned array is an amalgamation of all field errors.
  2051. * The additional validation checks are testing that the date format is valid, that the chosen
  2052. * date is within the min and max date constraints set, that the date chosen is not in the disabledDates
  2053. * regex and that the day chosed is not one of the disabledDays.
  2054. * @param {Mixed} value The value to get errors for (defaults to the current field value)
  2055. * @return {Array} All validation errors for this field
  2056. */
  2057. getErrors: function(value) {
  2058. var errors = Ext.form.DateField.superclass.getErrors.apply(this, arguments);
  2059. value = this.formatDate(value || this.processValue(this.getRawValue()));
  2060. if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
  2061. return errors;
  2062. }
  2063. var svalue = value;
  2064. value = this.parseDate(value);
  2065. if (!value) {
  2066. errors.push(String.format(this.invalidText, svalue, this.format));
  2067. return errors;
  2068. }
  2069. var time = value.getTime();
  2070. if (this.minValue && time < this.minValue.clearTime().getTime()) {
  2071. errors.push(String.format(this.minText, this.formatDate(this.minValue)));
  2072. }
  2073. if (this.maxValue && time > this.maxValue.clearTime().getTime()) {
  2074. errors.push(String.format(this.maxText, this.formatDate(this.maxValue)));
  2075. }
  2076. if (this.disabledDays) {
  2077. var day = value.getDay();
  2078. for(var i = 0; i < this.disabledDays.length; i++) {
  2079. if (day === this.disabledDays[i]) {
  2080. errors.push(this.disabledDaysText);
  2081. break;
  2082. }
  2083. }
  2084. }
  2085. var fvalue = this.formatDate(value);
  2086. if (this.disabledDatesRE && this.disabledDatesRE.test(fvalue)) {
  2087. errors.push(String.format(this.disabledDatesText, fvalue));
  2088. }
  2089. return errors;
  2090. },
  2091. // private
  2092. // Provides logic to override the default TriggerField.validateBlur which just returns true
  2093. validateBlur : function(){
  2094. return !this.menu || !this.menu.isVisible();
  2095. },
  2096. /**
  2097. * Returns the current date value of the date field.
  2098. * @return {Date} The date value
  2099. */
  2100. getValue : function(){
  2101. return this.parseDate(Ext.form.DateField.superclass.getValue.call(this)) || "";
  2102. },
  2103. /**
  2104. * Sets the value of the date field. You can pass a date object or any string that can be
  2105. * parsed into a valid date, using <tt>{@link #format}</tt> as the date format, according
  2106. * to the same rules as {@link Date#parseDate} (the default format used is <tt>"m/d/Y"</tt>).
  2107. * <br />Usage:
  2108. * <pre><code>
  2109. //All of these calls set the same date value (May 4, 2006)
  2110. //Pass a date object:
  2111. var dt = new Date('5/4/2006');
  2112. dateField.setValue(dt);
  2113. //Pass a date string (default format):
  2114. dateField.setValue('05/04/2006');
  2115. //Pass a date string (custom format):
  2116. dateField.format = 'Y-m-d';
  2117. dateField.setValue('2006-05-04');
  2118. </code></pre>
  2119. * @param {String/Date} date The date or valid date string
  2120. * @return {Ext.form.Field} this
  2121. */
  2122. setValue : function(date){
  2123. return Ext.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
  2124. },
  2125. // private
  2126. parseDate : function(value) {
  2127. if(!value || Ext.isDate(value)){
  2128. return value;
  2129. }
  2130. var v = this.safeParse(value, this.format),
  2131. af = this.altFormats,
  2132. afa = this.altFormatsArray;
  2133. if (!v && af) {
  2134. afa = afa || af.split("|");
  2135. for (var i = 0, len = afa.length; i < len && !v; i++) {
  2136. v = this.safeParse(value, afa[i]);
  2137. }
  2138. }
  2139. return v;
  2140. },
  2141. // private
  2142. onDestroy : function(){
  2143. Ext.destroy(this.menu, this.keyNav);
  2144. Ext.form.DateField.superclass.onDestroy.call(this);
  2145. },
  2146. // private
  2147. formatDate : function(date){
  2148. return Ext.isDate(date) ? date.dateFormat(this.format) : date;
  2149. },
  2150. /**
  2151. * @method onTriggerClick
  2152. * @hide
  2153. */
  2154. // private
  2155. // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
  2156. onTriggerClick : function(){
  2157. if(this.disabled){
  2158. return;
  2159. }
  2160. if(this.menu == null){
  2161. this.menu = new Ext.menu.DateMenu({
  2162. hideOnClick: false,
  2163. focusOnSelect: false
  2164. });
  2165. }
  2166. this.onFocus();
  2167. Ext.apply(this.menu.picker, {
  2168. minDate : this.minValue,
  2169. maxDate : this.maxValue,
  2170. disabledDatesRE : this.disabledDatesRE,
  2171. disabledDatesText : this.disabledDatesText,
  2172. disabledDays : this.disabledDays,
  2173. disabledDaysText : this.disabledDaysText,
  2174. format : this.format,
  2175. showToday : this.showToday,
  2176. startDay: this.startDay,
  2177. minText : String.format(this.minText, this.formatDate(this.minValue)),
  2178. maxText : String.format(this.maxText, this.formatDate(this.maxValue))
  2179. });
  2180. this.menu.picker.setValue(this.getValue() || new Date());
  2181. this.menu.show(this.el, "tl-bl?");
  2182. this.menuEvents('on');
  2183. },
  2184. //private
  2185. menuEvents: function(method){
  2186. this.menu[method]('select', this.onSelect, this);
  2187. this.menu[method]('hide', this.onMenuHide, this);
  2188. this.menu[method]('show', this.onFocus, this);
  2189. },
  2190. onSelect: function(m, d){
  2191. this.setValue(d);
  2192. this.fireEvent('select', this, d);
  2193. this.menu.hide();
  2194. },
  2195. onMenuHide: function(){
  2196. this.focus(false, 60);
  2197. this.menuEvents('un');
  2198. },
  2199. // private
  2200. beforeBlur : function(){
  2201. var v = this.parseDate(this.getRawValue());
  2202. if(v){
  2203. this.setValue(v);
  2204. }
  2205. }
  2206. /**
  2207. * @cfg {Boolean} grow @hide
  2208. */
  2209. /**
  2210. * @cfg {Number} growMin @hide
  2211. */
  2212. /**
  2213. * @cfg {Number} growMax @hide
  2214. */
  2215. /**
  2216. * @hide
  2217. * @method autoSize
  2218. */
  2219. });
  2220. Ext.reg('datefield', Ext.form.DateField);
  2221. /**
  2222. * @class Ext.form.DisplayField
  2223. * @extends Ext.form.Field
  2224. * A display-only text field which is not validated and not submitted.
  2225. * @constructor
  2226. * Creates a new DisplayField.
  2227. * @param {Object} config Configuration options
  2228. * @xtype displayfield
  2229. */
  2230. Ext.form.DisplayField = Ext.extend(Ext.form.Field, {
  2231. validationEvent : false,
  2232. validateOnBlur : false,
  2233. defaultAutoCreate : {tag: "div"},
  2234. /**
  2235. * @cfg {String} fieldClass The default CSS class for the field (defaults to <tt>"x-form-display-field"</tt>)
  2236. */
  2237. fieldClass : "x-form-display-field",
  2238. /**
  2239. * @cfg {Boolean} htmlEncode <tt>false</tt> to skip HTML-encoding the text when rendering it (defaults to
  2240. * <tt>false</tt>). This might be useful if you want to include tags in the field's innerHTML rather than
  2241. * rendering them as string literals per the default logic.
  2242. */
  2243. htmlEncode: false,
  2244. // private
  2245. initEvents : Ext.emptyFn,
  2246. isValid : function(){
  2247. return true;
  2248. },
  2249. validate : function(){
  2250. return true;
  2251. },
  2252. getRawValue : function(){
  2253. var v = this.rendered ? this.el.dom.innerHTML : Ext.value(this.value, '');
  2254. if(v === this.emptyText){
  2255. v = '';
  2256. }
  2257. if(this.htmlEncode){
  2258. v = Ext.util.Format.htmlDecode(v);
  2259. }
  2260. return v;
  2261. },
  2262. getValue : function(){
  2263. return this.getRawValue();
  2264. },
  2265. getName: function() {
  2266. return this.name;
  2267. },
  2268. setRawValue : function(v){
  2269. if(this.htmlEncode){
  2270. v = Ext.util.Format.htmlEncode(v);
  2271. }
  2272. return this.rendered ? (this.el.dom.innerHTML = (Ext.isEmpty(v) ? '' : v)) : (this.value = v);
  2273. },
  2274. setValue : function(v){
  2275. this.setRawValue(v);
  2276. return this;
  2277. }
  2278. /**
  2279. * @cfg {String} inputType
  2280. * @hide
  2281. */
  2282. /**
  2283. * @cfg {Boolean} disabled
  2284. * @hide
  2285. */
  2286. /**
  2287. * @cfg {Boolean} readOnly
  2288. * @hide
  2289. */
  2290. /**
  2291. * @cfg {Boolean} validateOnBlur
  2292. * @hide
  2293. */
  2294. /**
  2295. * @cfg {Number} validationDelay
  2296. * @hide
  2297. */
  2298. /**
  2299. * @cfg {String/Boolean} validationEvent
  2300. * @hide
  2301. */
  2302. });
  2303. Ext.reg('displayfield', Ext.form.DisplayField);
  2304. /**
  2305. * @class Ext.form.ComboBox
  2306. * @extends Ext.form.TriggerField
  2307. * <p>A combobox control with support for autocomplete, remote-loading, paging and many other features.</p>
  2308. * <p>A ComboBox works in a similar manner to a traditional HTML &lt;select> field. The difference is
  2309. * that to submit the {@link #valueField}, you must specify a {@link #hiddenName} to create a hidden input
  2310. * field to hold the value of the valueField. The <i>{@link #displayField}</i> is shown in the text field
  2311. * which is named according to the {@link #name}.</p>
  2312. * <p><b><u>Events</u></b></p>
  2313. * <p>To do something when something in ComboBox is selected, configure the select event:<pre><code>
  2314. var cb = new Ext.form.ComboBox({
  2315. // all of your config options
  2316. listeners:{
  2317. scope: yourScope,
  2318. 'select': yourFunction
  2319. }
  2320. });
  2321. // Alternatively, you can assign events after the object is created:
  2322. var cb = new Ext.form.ComboBox(yourOptions);
  2323. cb.on('select', yourFunction, yourScope);
  2324. * </code></pre></p>
  2325. *
  2326. * <p><b><u>ComboBox in Grid</u></b></p>
  2327. * <p>If using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a {@link Ext.grid.Column#renderer renderer}
  2328. * will be needed to show the displayField when the editor is not active. Set up the renderer manually, or implement
  2329. * a reusable render, for example:<pre><code>
  2330. // create reusable renderer
  2331. Ext.util.Format.comboRenderer = function(combo){
  2332. return function(value){
  2333. var record = combo.findRecord(combo.{@link #valueField}, value);
  2334. return record ? record.get(combo.{@link #displayField}) : combo.{@link #valueNotFoundText};
  2335. }
  2336. }
  2337. // create the combo instance
  2338. var combo = new Ext.form.ComboBox({
  2339. {@link #typeAhead}: true,
  2340. {@link #triggerAction}: 'all',
  2341. {@link #lazyRender}:true,
  2342. {@link #mode}: 'local',
  2343. {@link #store}: new Ext.data.ArrayStore({
  2344. id: 0,
  2345. fields: [
  2346. 'myId',
  2347. 'displayText'
  2348. ],
  2349. data: [[1, 'item1'], [2, 'item2']]
  2350. }),
  2351. {@link #valueField}: 'myId',
  2352. {@link #displayField}: 'displayText'
  2353. });
  2354. // snippet of column model used within grid
  2355. var cm = new Ext.grid.ColumnModel([{
  2356. ...
  2357. },{
  2358. header: "Some Header",
  2359. dataIndex: 'whatever',
  2360. width: 130,
  2361. editor: combo, // specify reference to combo instance
  2362. renderer: Ext.util.Format.comboRenderer(combo) // pass combo instance to reusable renderer
  2363. },
  2364. ...
  2365. ]);
  2366. * </code></pre></p>
  2367. *
  2368. * <p><b><u>Filtering</u></b></p>
  2369. * <p>A ComboBox {@link #doQuery uses filtering itself}, for information about filtering the ComboBox
  2370. * store manually see <tt>{@link #lastQuery}</tt>.</p>
  2371. * @constructor
  2372. * Create a new ComboBox.
  2373. * @param {Object} config Configuration options
  2374. * @xtype combo
  2375. */
  2376. Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {
  2377. /**
  2378. * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.
  2379. * Note that if you specify this and the combo is going to be in an {@link Ext.form.BasicForm} or
  2380. * {@link Ext.form.FormPanel}, you must also set <tt>{@link #lazyRender} = true</tt>.
  2381. */
  2382. /**
  2383. * @cfg {Boolean} lazyRender <tt>true</tt> to prevent the ComboBox from rendering until requested
  2384. * (should always be used when rendering into an {@link Ext.Editor} (e.g. {@link Ext.grid.EditorGridPanel Grids}),
  2385. * defaults to <tt>false</tt>).
  2386. */
  2387. /**
  2388. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or <tt>true</tt> for a default
  2389. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  2390. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  2391. * <pre><code>{tag: "input", type: "text", size: "24", autocomplete: "off"}</code></pre>
  2392. */
  2393. /**
  2394. * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to <tt>undefined</tt>).
  2395. * Acceptable values for this property are:
  2396. * <div class="mdetail-params"><ul>
  2397. * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
  2398. * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally,
  2399. * automatically generating {@link Ext.data.Field#name field names} to work with all data components.
  2400. * <div class="mdetail-params"><ul>
  2401. * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
  2402. * A 1-dimensional array will automatically be expanded (each array item will be used for both the combo
  2403. * {@link #valueField} and {@link #displayField})</div></li>
  2404. * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
  2405. * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
  2406. * {@link #valueField}, while the value at index 1 is assumed to be the combo {@link #displayField}.
  2407. * </div></li></ul></div></li></ul></div>
  2408. * <p>See also <tt>{@link #mode}</tt>.</p>
  2409. */
  2410. /**
  2411. * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
  2412. * the dropdown list (defaults to undefined, with no header element)
  2413. */
  2414. // private
  2415. defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
  2416. /**
  2417. * @cfg {Number} listWidth The width (used as a parameter to {@link Ext.Element#setWidth}) of the dropdown
  2418. * list (defaults to the width of the ComboBox field). See also <tt>{@link #minListWidth}
  2419. */
  2420. /**
  2421. * @cfg {String} displayField The underlying {@link Ext.data.Field#name data field name} to bind to this
  2422. * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field1'</tt> if
  2423. * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
  2424. * the store configuration}).
  2425. * <p>See also <tt>{@link #valueField}</tt>.</p>
  2426. * <p><b>Note</b>: if using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a
  2427. * {@link Ext.grid.Column#renderer renderer} will be needed to show the displayField when the editor is not
  2428. * active.</p>
  2429. */
  2430. /**
  2431. * @cfg {String} valueField The underlying {@link Ext.data.Field#name data value name} to bind to this
  2432. * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field2'</tt> if
  2433. * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
  2434. * the store configuration}).
  2435. * <p><b>Note</b>: use of a <tt>valueField</tt> requires the user to make a selection in order for a value to be
  2436. * mapped. See also <tt>{@link #hiddenName}</tt>, <tt>{@link #hiddenValue}</tt>, and <tt>{@link #displayField}</tt>.</p>
  2437. */
  2438. /**
  2439. * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
  2440. * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically
  2441. * post during a form submission. See also {@link #valueField}.
  2442. */
  2443. /**
  2444. * @cfg {String} hiddenId If <tt>{@link #hiddenName}</tt> is specified, <tt>hiddenId</tt> can also be provided
  2445. * to give the hidden field a unique id. The <tt>hiddenId</tt> and combo {@link Ext.Component#id id} should be
  2446. * different, since no two DOM nodes should share the same id.
  2447. */
  2448. /**
  2449. * @cfg {String} hiddenValue Sets the initial value of the hidden field if {@link #hiddenName} is
  2450. * specified to contain the selected {@link #valueField}, from the Store. Defaults to the configured
  2451. * <tt>{@link Ext.form.Field#value value}</tt>.
  2452. */
  2453. /**
  2454. * @cfg {String} listClass The CSS class to add to the predefined <tt>'x-combo-list'</tt> class
  2455. * applied the dropdown list element (defaults to '').
  2456. */
  2457. listClass : '',
  2458. /**
  2459. * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list
  2460. * (defaults to <tt>'x-combo-selected'</tt>)
  2461. */
  2462. selectedClass : 'x-combo-selected',
  2463. /**
  2464. * @cfg {String} listEmptyText The empty text to display in the data view if no items are found.
  2465. * (defaults to '')
  2466. */
  2467. listEmptyText: '',
  2468. /**
  2469. * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always
  2470. * get the class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
  2471. * (defaults to <tt>'x-form-arrow-trigger'</tt> which displays a downward arrow icon).
  2472. */
  2473. triggerClass : 'x-form-arrow-trigger',
  2474. /**
  2475. * @cfg {Boolean/String} shadow <tt>true</tt> or <tt>"sides"</tt> for the default effect, <tt>"frame"</tt> for
  2476. * 4-way shadow, and <tt>"drop"</tt> for bottom-right
  2477. */
  2478. shadow : 'sides',
  2479. /**
  2480. * @cfg {String/Array} listAlign A valid anchor position value. See <tt>{@link Ext.Element#alignTo}</tt> for details
  2481. * on supported anchor positions and offsets. To specify x/y offsets as well, this value
  2482. * may be specified as an Array of <tt>{@link Ext.Element#alignTo}</tt> method arguments.</p>
  2483. * <pre><code>[ 'tl-bl?', [6,0] ]</code></pre>(defaults to <tt>'tl-bl?'</tt>)
  2484. */
  2485. listAlign : 'tl-bl?',
  2486. /**
  2487. * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown
  2488. * (defaults to <tt>300</tt>)
  2489. */
  2490. maxHeight : 300,
  2491. /**
  2492. * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its
  2493. * distance to the viewport edges (defaults to <tt>90</tt>)
  2494. */
  2495. minHeight : 90,
  2496. /**
  2497. * @cfg {String} triggerAction The action to execute when the trigger is clicked.
  2498. * <div class="mdetail-params"><ul>
  2499. * <li><b><tt>'query'</tt></b> : <b>Default</b>
  2500. * <p class="sub-desc">{@link #doQuery run the query} using the {@link Ext.form.Field#getRawValue raw value}.</p></li>
  2501. * <li><b><tt>'all'</tt></b> :
  2502. * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>
  2503. * </ul></div>
  2504. * <p>See also <code>{@link #queryParam}</code>.</p>
  2505. */
  2506. triggerAction : 'query',
  2507. /**
  2508. * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and
  2509. * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #mode} = 'remote'</tt> or <tt>0</tt> if
  2510. * <tt>{@link #mode} = 'local'</tt>, does not apply if
  2511. * <tt>{@link Ext.form.TriggerField#editable editable} = false</tt>).
  2512. */
  2513. minChars : 4,
  2514. /**
  2515. * @cfg {Boolean} autoSelect <tt>true</tt> to select the first result gathered by the data store (defaults
  2516. * to <tt>true</tt>). A false value would require a manual selection from the dropdown list to set the components value
  2517. * unless the value of ({@link #typeAheadDelay}) were true.
  2518. */
  2519. autoSelect : true,
  2520. /**
  2521. * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being
  2522. * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults
  2523. * to <tt>false</tt>)
  2524. */
  2525. typeAhead : false,
  2526. /**
  2527. * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and
  2528. * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #mode} = 'remote'</tt>
  2529. * or <tt>10</tt> if <tt>{@link #mode} = 'local'</tt>)
  2530. */
  2531. queryDelay : 500,
  2532. /**
  2533. * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.PagingToolbar} is displayed in the
  2534. * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and
  2535. * {@link Ext.PagingToolbar#pageSize limit} parameters. Only applies when <tt>{@link #mode} = 'remote'</tt>
  2536. * (defaults to <tt>0</tt>).
  2537. */
  2538. pageSize : 0,
  2539. /**
  2540. * @cfg {Boolean} selectOnFocus <tt>true</tt> to select any existing text in the field immediately on focus.
  2541. * Only applies when <tt>{@link Ext.form.TriggerField#editable editable} = true</tt> (defaults to
  2542. * <tt>false</tt>).
  2543. */
  2544. selectOnFocus : false,
  2545. /**
  2546. * @cfg {String} queryParam Name of the query ({@link Ext.data.Store#baseParam baseParam} name for the store)
  2547. * as it will be passed on the querystring (defaults to <tt>'query'</tt>)
  2548. */
  2549. queryParam : 'query',
  2550. /**
  2551. * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
  2552. * when <tt>{@link #mode} = 'remote'</tt> (defaults to <tt>'Loading...'</tt>)
  2553. */
  2554. loadingText : 'Loading...',
  2555. /**
  2556. * @cfg {Boolean} resizable <tt>true</tt> to add a resize handle to the bottom of the dropdown list
  2557. * (creates an {@link Ext.Resizable} with 'se' {@link Ext.Resizable#pinned pinned} handles).
  2558. * Defaults to <tt>false</tt>.
  2559. */
  2560. resizable : false,
  2561. /**
  2562. * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if
  2563. * <tt>{@link #resizable} = true</tt> (defaults to <tt>8</tt>)
  2564. */
  2565. handleHeight : 8,
  2566. /**
  2567. * @cfg {String} allQuery The text query to send to the server to return all records for the list
  2568. * with no filtering (defaults to '')
  2569. */
  2570. allQuery: '',
  2571. /**
  2572. * @cfg {String} mode Acceptable values are:
  2573. * <div class="mdetail-params"><ul>
  2574. * <li><b><tt>'remote'</tt></b> : <b>Default</b>
  2575. * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger
  2576. * is clicked. If you do not want the store to be automatically loaded the first time the trigger is
  2577. * clicked, set to <tt>'local'</tt> and manually load the store. To force a requery of the store
  2578. * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>
  2579. * <li><b><tt>'local'</tt></b> :
  2580. * <p class="sub-desc">ComboBox loads local data</p>
  2581. * <pre><code>
  2582. var combo = new Ext.form.ComboBox({
  2583. renderTo: document.body,
  2584. mode: 'local',
  2585. store: new Ext.data.ArrayStore({
  2586. id: 0,
  2587. fields: [
  2588. 'myId', // numeric value is the key
  2589. 'displayText'
  2590. ],
  2591. data: [[1, 'item1'], [2, 'item2']] // data is local
  2592. }),
  2593. valueField: 'myId',
  2594. displayField: 'displayText',
  2595. triggerAction: 'all'
  2596. });
  2597. * </code></pre></li>
  2598. * </ul></div>
  2599. */
  2600. mode: 'remote',
  2601. /**
  2602. * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to <tt>70</tt>, will
  2603. * be ignored if <tt>{@link #listWidth}</tt> has a higher value)
  2604. */
  2605. minListWidth : 70,
  2606. /**
  2607. * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,
  2608. * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)
  2609. */
  2610. forceSelection : false,
  2611. /**
  2612. * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
  2613. * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)
  2614. */
  2615. typeAheadDelay : 250,
  2616. /**
  2617. * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
  2618. * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this
  2619. * default text is used, it means there is no value set and no validation will occur on this field.
  2620. */
  2621. /**
  2622. * @cfg {Boolean} lazyInit <tt>true</tt> to not initialize the list for this combo until the field is focused
  2623. * (defaults to <tt>true</tt>)
  2624. */
  2625. lazyInit : true,
  2626. /**
  2627. * @cfg {Boolean} clearFilterOnReset <tt>true</tt> to clear any filters on the store (when in local mode) when reset is called
  2628. * (defaults to <tt>true</tt>)
  2629. */
  2630. clearFilterOnReset : true,
  2631. /**
  2632. * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
  2633. * If a hiddenName is specified, setting this to true will cause both the hidden field and the element to be submitted.
  2634. * Defaults to <tt>undefined</tt>.
  2635. */
  2636. submitValue: undefined,
  2637. /**
  2638. * The value of the match string used to filter the store. Delete this property to force a requery.
  2639. * Example use:
  2640. * <pre><code>
  2641. var combo = new Ext.form.ComboBox({
  2642. ...
  2643. mode: 'remote',
  2644. ...
  2645. listeners: {
  2646. // delete the previous query in the beforequery event or set
  2647. // combo.lastQuery = null (this will reload the store the next time it expands)
  2648. beforequery: function(qe){
  2649. delete qe.combo.lastQuery;
  2650. }
  2651. }
  2652. });
  2653. * </code></pre>
  2654. * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used
  2655. * configure the combo with <tt>lastQuery=''</tt>. Example use:
  2656. * <pre><code>
  2657. var combo = new Ext.form.ComboBox({
  2658. ...
  2659. mode: 'local',
  2660. triggerAction: 'all',
  2661. lastQuery: ''
  2662. });
  2663. * </code></pre>
  2664. * @property lastQuery
  2665. * @type String
  2666. */
  2667. // private
  2668. initComponent : function(){
  2669. Ext.form.ComboBox.superclass.initComponent.call(this);
  2670. this.addEvents(
  2671. /**
  2672. * @event expand
  2673. * Fires when the dropdown list is expanded
  2674. * @param {Ext.form.ComboBox} combo This combo box
  2675. */
  2676. 'expand',
  2677. /**
  2678. * @event collapse
  2679. * Fires when the dropdown list is collapsed
  2680. * @param {Ext.form.ComboBox} combo This combo box
  2681. */
  2682. 'collapse',
  2683. /**
  2684. * @event beforeselect
  2685. * Fires before a list item is selected. Return false to cancel the selection.
  2686. * @param {Ext.form.ComboBox} combo This combo box
  2687. * @param {Ext.data.Record} record The data record returned from the underlying store
  2688. * @param {Number} index The index of the selected item in the dropdown list
  2689. */
  2690. 'beforeselect',
  2691. /**
  2692. * @event select
  2693. * Fires when a list item is selected
  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. 'select',
  2699. /**
  2700. * @event beforequery
  2701. * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
  2702. * cancel property to true.
  2703. * @param {Object} queryEvent An object that has these properties:<ul>
  2704. * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>
  2705. * <li><code>query</code> : String <div class="sub-desc">The query</div></li>
  2706. * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
  2707. * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
  2708. * </ul>
  2709. */
  2710. 'beforequery'
  2711. );
  2712. if(this.transform){
  2713. var s = Ext.getDom(this.transform);
  2714. if(!this.hiddenName){
  2715. this.hiddenName = s.name;
  2716. }
  2717. if(!this.store){
  2718. this.mode = 'local';
  2719. var d = [], opts = s.options;
  2720. for(var i = 0, len = opts.length;i < len; i++){
  2721. var o = opts[i],
  2722. value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttributeNode('value').specified) ? o.value : o.text;
  2723. if(o.selected && Ext.isEmpty(this.value, true)) {
  2724. this.value = value;
  2725. }
  2726. d.push([value, o.text]);
  2727. }
  2728. this.store = new Ext.data.ArrayStore({
  2729. idIndex: 0,
  2730. fields: ['value', 'text'],
  2731. data : d,
  2732. autoDestroy: true
  2733. });
  2734. this.valueField = 'value';
  2735. this.displayField = 'text';
  2736. }
  2737. s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference
  2738. if(!this.lazyRender){
  2739. this.target = true;
  2740. this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
  2741. this.render(this.el.parentNode, s);
  2742. }
  2743. Ext.removeNode(s);
  2744. }
  2745. //auto-configure store from local array data
  2746. else if(this.store){
  2747. this.store = Ext.StoreMgr.lookup(this.store);
  2748. if(this.store.autoCreated){
  2749. this.displayField = this.valueField = 'field1';
  2750. if(!this.store.expandData){
  2751. this.displayField = 'field2';
  2752. }
  2753. this.mode = 'local';
  2754. }
  2755. }
  2756. this.selectedIndex = -1;
  2757. if(this.mode == 'local'){
  2758. if(!Ext.isDefined(this.initialConfig.queryDelay)){
  2759. this.queryDelay = 10;
  2760. }
  2761. if(!Ext.isDefined(this.initialConfig.minChars)){
  2762. this.minChars = 0;
  2763. }
  2764. }
  2765. },
  2766. // private
  2767. onRender : function(ct, position){
  2768. if(this.hiddenName && !Ext.isDefined(this.submitValue)){
  2769. this.submitValue = false;
  2770. }
  2771. Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
  2772. if(this.hiddenName){
  2773. this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName,
  2774. id: (this.hiddenId || Ext.id())}, 'before', true);
  2775. }
  2776. if(Ext.isGecko){
  2777. this.el.dom.setAttribute('autocomplete', 'off');
  2778. }
  2779. if(!this.lazyInit){
  2780. this.initList();
  2781. }else{
  2782. this.on('focus', this.initList, this, {single: true});
  2783. }
  2784. },
  2785. // private
  2786. initValue : function(){
  2787. Ext.form.ComboBox.superclass.initValue.call(this);
  2788. if(this.hiddenField){
  2789. this.hiddenField.value =
  2790. Ext.value(Ext.isDefined(this.hiddenValue) ? this.hiddenValue : this.value, '');
  2791. }
  2792. },
  2793. getParentZIndex : function(){
  2794. var zindex;
  2795. if (this.ownerCt){
  2796. this.findParentBy(function(ct){
  2797. zindex = parseInt(ct.getPositionEl().getStyle('z-index'), 10);
  2798. return !!zindex;
  2799. });
  2800. }
  2801. return zindex;
  2802. },
  2803. getZIndex : function(listParent){
  2804. listParent = listParent || Ext.getDom(this.getListParent() || Ext.getBody());
  2805. var zindex = parseInt(Ext.fly(listParent).getStyle('z-index'), 10);
  2806. if(!zindex){
  2807. zindex = this.getParentZIndex();
  2808. }
  2809. return (zindex || 12000) + 5;
  2810. },
  2811. // private
  2812. initList : function(){
  2813. if(!this.list){
  2814. var cls = 'x-combo-list',
  2815. listParent = Ext.getDom(this.getListParent() || Ext.getBody());
  2816. this.list = new Ext.Layer({
  2817. parentEl: listParent,
  2818. shadow: this.shadow,
  2819. cls: [cls, this.listClass].join(' '),
  2820. constrain:false,
  2821. zindex: this.getZIndex(listParent)
  2822. });
  2823. var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
  2824. this.list.setSize(lw, 0);
  2825. this.list.swallowEvent('mousewheel');
  2826. this.assetHeight = 0;
  2827. if(this.syncFont !== false){
  2828. this.list.setStyle('font-size', this.el.getStyle('font-size'));
  2829. }
  2830. if(this.title){
  2831. this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
  2832. this.assetHeight += this.header.getHeight();
  2833. }
  2834. this.innerList = this.list.createChild({cls:cls+'-inner'});
  2835. this.mon(this.innerList, 'mouseover', this.onViewOver, this);
  2836. this.mon(this.innerList, 'mousemove', this.onViewMove, this);
  2837. this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
  2838. if(this.pageSize){
  2839. this.footer = this.list.createChild({cls:cls+'-ft'});
  2840. this.pageTb = new Ext.PagingToolbar({
  2841. store: this.store,
  2842. pageSize: this.pageSize,
  2843. renderTo:this.footer
  2844. });
  2845. this.assetHeight += this.footer.getHeight();
  2846. }
  2847. if(!this.tpl){
  2848. /**
  2849. * @cfg {String/Ext.XTemplate} tpl <p>The template string, or {@link Ext.XTemplate} instance to
  2850. * use to display each item in the dropdown list. The dropdown list is displayed in a
  2851. * DataView. See {@link #view}.</p>
  2852. * <p>The default template string is:</p><pre><code>
  2853. '&lt;tpl for=".">&lt;div class="x-combo-list-item">{' + this.displayField + '}&lt;/div>&lt;/tpl>'
  2854. * </code></pre>
  2855. * <p>Override the default value to create custom UI layouts for items in the list.
  2856. * For example:</p><pre><code>
  2857. '&lt;tpl for=".">&lt;div ext:qtip="{state}. {nick}" class="x-combo-list-item">{state}&lt;/div>&lt;/tpl>'
  2858. * </code></pre>
  2859. * <p>The template <b>must</b> contain one or more substitution parameters using field
  2860. * names from the Combo's</b> {@link #store Store}. In the example above an
  2861. * <pre>ext:qtip</pre> attribute is added to display other fields from the Store.</p>
  2862. * <p>To preserve the default visual look of list items, add the CSS class name
  2863. * <pre>x-combo-list-item</pre> to the template's container element.</p>
  2864. * <p>Also see {@link #itemSelector} for additional details.</p>
  2865. */
  2866. this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>';
  2867. /**
  2868. * @cfg {String} itemSelector
  2869. * <p>A simple CSS selector (e.g. div.some-class or span:first-child) that will be
  2870. * used to determine what nodes the {@link #view Ext.DataView} which handles the dropdown
  2871. * display will be working with.</p>
  2872. * <p><b>Note</b>: this setting is <b>required</b> if a custom XTemplate has been
  2873. * specified in {@link #tpl} which assigns a class other than <pre>'x-combo-list-item'</pre>
  2874. * to dropdown list items</b>
  2875. */
  2876. }
  2877. /**
  2878. * The {@link Ext.DataView DataView} used to display the ComboBox's options.
  2879. * @type Ext.DataView
  2880. */
  2881. this.view = new Ext.DataView({
  2882. applyTo: this.innerList,
  2883. tpl: this.tpl,
  2884. singleSelect: true,
  2885. selectedClass: this.selectedClass,
  2886. itemSelector: this.itemSelector || '.' + cls + '-item',
  2887. emptyText: this.listEmptyText,
  2888. deferEmptyText: false
  2889. });
  2890. this.mon(this.view, {
  2891. containerclick : this.onViewClick,
  2892. click : this.onViewClick,
  2893. scope :this
  2894. });
  2895. this.bindStore(this.store, true);
  2896. if(this.resizable){
  2897. this.resizer = new Ext.Resizable(this.list, {
  2898. pinned:true, handles:'se'
  2899. });
  2900. this.mon(this.resizer, 'resize', function(r, w, h){
  2901. this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
  2902. this.listWidth = w;
  2903. this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
  2904. this.restrictHeight();
  2905. }, this);
  2906. this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
  2907. }
  2908. }
  2909. },
  2910. /**
  2911. * <p>Returns the element used to house this ComboBox's pop-up list. Defaults to the document body.</p>
  2912. * A custom implementation may be provided as a configuration option if the floating list needs to be rendered
  2913. * to a different Element. An example might be rendering the list inside a Menu so that clicking
  2914. * the list does not hide the Menu:<pre><code>
  2915. var store = new Ext.data.ArrayStore({
  2916. autoDestroy: true,
  2917. fields: ['initials', 'fullname'],
  2918. data : [
  2919. ['FF', 'Fred Flintstone'],
  2920. ['BR', 'Barney Rubble']
  2921. ]
  2922. });
  2923. var combo = new Ext.form.ComboBox({
  2924. store: store,
  2925. displayField: 'fullname',
  2926. emptyText: 'Select a name...',
  2927. forceSelection: true,
  2928. getListParent: function() {
  2929. return this.el.up('.x-menu');
  2930. },
  2931. iconCls: 'no-icon', //use iconCls if placing within menu to shift to right side of menu
  2932. mode: 'local',
  2933. selectOnFocus: true,
  2934. triggerAction: 'all',
  2935. typeAhead: true,
  2936. width: 135
  2937. });
  2938. var menu = new Ext.menu.Menu({
  2939. id: 'mainMenu',
  2940. items: [
  2941. combo // A Field in a Menu
  2942. ]
  2943. });
  2944. </code></pre>
  2945. */
  2946. getListParent : function() {
  2947. return document.body;
  2948. },
  2949. /**
  2950. * Returns the store associated with this combo.
  2951. * @return {Ext.data.Store} The store
  2952. */
  2953. getStore : function(){
  2954. return this.store;
  2955. },
  2956. // private
  2957. bindStore : function(store, initial){
  2958. if(this.store && !initial){
  2959. if(this.store !== store && this.store.autoDestroy){
  2960. this.store.destroy();
  2961. }else{
  2962. this.store.un('beforeload', this.onBeforeLoad, this);
  2963. this.store.un('load', this.onLoad, this);
  2964. this.store.un('exception', this.collapse, this);
  2965. }
  2966. if(!store){
  2967. this.store = null;
  2968. if(this.view){
  2969. this.view.bindStore(null);
  2970. }
  2971. if(this.pageTb){
  2972. this.pageTb.bindStore(null);
  2973. }
  2974. }
  2975. }
  2976. if(store){
  2977. if(!initial) {
  2978. this.lastQuery = null;
  2979. if(this.pageTb) {
  2980. this.pageTb.bindStore(store);
  2981. }
  2982. }
  2983. this.store = Ext.StoreMgr.lookup(store);
  2984. this.store.on({
  2985. scope: this,
  2986. beforeload: this.onBeforeLoad,
  2987. load: this.onLoad,
  2988. exception: this.collapse
  2989. });
  2990. if(this.view){
  2991. this.view.bindStore(store);
  2992. }
  2993. }
  2994. },
  2995. reset : function(){
  2996. if(this.clearFilterOnReset && this.mode == 'local'){
  2997. this.store.clearFilter();
  2998. }
  2999. Ext.form.ComboBox.superclass.reset.call(this);
  3000. },
  3001. // private
  3002. initEvents : function(){
  3003. Ext.form.ComboBox.superclass.initEvents.call(this);
  3004. /**
  3005. * @property keyNav
  3006. * @type Ext.KeyNav
  3007. * <p>A {@link Ext.KeyNav KeyNav} object which handles navigation keys for this ComboBox. This performs actions
  3008. * based on keystrokes typed when the input field is focused.</p>
  3009. * <p><b>After the ComboBox has been rendered</b>, you may override existing navigation key functionality,
  3010. * or add your own based upon key names as specified in the {@link Ext.KeyNav KeyNav} class.</p>
  3011. * <p>The function is executed in the scope (<code>this</code> reference of the ComboBox. Example:</p><pre><code>
  3012. myCombo.keyNav.esc = function(e) { // Override ESC handling function
  3013. this.collapse(); // Standard behaviour of Ext's ComboBox.
  3014. this.setValue(this.startValue); // We reset to starting value on ESC
  3015. };
  3016. myCombo.keyNav.tab = function() { // Override TAB handling function
  3017. this.onViewClick(false); // Select the currently highlighted row
  3018. };
  3019. </code></pre>
  3020. */
  3021. this.keyNav = new Ext.KeyNav(this.el, {
  3022. "up" : function(e){
  3023. this.inKeyMode = true;
  3024. this.selectPrev();
  3025. },
  3026. "down" : function(e){
  3027. if(!this.isExpanded()){
  3028. this.onTriggerClick();
  3029. }else{
  3030. this.inKeyMode = true;
  3031. this.selectNext();
  3032. }
  3033. },
  3034. "enter" : function(e){
  3035. this.onViewClick();
  3036. },
  3037. "esc" : function(e){
  3038. this.collapse();
  3039. },
  3040. "tab" : function(e){
  3041. if (this.forceSelection === true) {
  3042. this.collapse();
  3043. } else {
  3044. this.onViewClick(false);
  3045. }
  3046. return true;
  3047. },
  3048. scope : this,
  3049. doRelay : function(e, h, hname){
  3050. if(hname == 'down' || this.scope.isExpanded()){
  3051. // this MUST be called before ComboBox#fireKey()
  3052. var relay = Ext.KeyNav.prototype.doRelay.apply(this, arguments);
  3053. if(!Ext.isIE && Ext.EventManager.useKeydown){
  3054. // call Combo#fireKey() for browsers which use keydown event (except IE)
  3055. this.scope.fireKey(e);
  3056. }
  3057. return relay;
  3058. }
  3059. return true;
  3060. },
  3061. forceKeyDown : true,
  3062. defaultEventAction: 'stopEvent'
  3063. });
  3064. this.queryDelay = Math.max(this.queryDelay || 10,
  3065. this.mode == 'local' ? 10 : 250);
  3066. this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
  3067. if(this.typeAhead){
  3068. this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
  3069. }
  3070. if(!this.enableKeyEvents){
  3071. this.mon(this.el, 'keyup', this.onKeyUp, this);
  3072. }
  3073. },
  3074. // private
  3075. onDestroy : function(){
  3076. if (this.dqTask){
  3077. this.dqTask.cancel();
  3078. this.dqTask = null;
  3079. }
  3080. this.bindStore(null);
  3081. Ext.destroy(
  3082. this.resizer,
  3083. this.view,
  3084. this.pageTb,
  3085. this.list
  3086. );
  3087. Ext.destroyMembers(this, 'hiddenField');
  3088. Ext.form.ComboBox.superclass.onDestroy.call(this);
  3089. },
  3090. // private
  3091. fireKey : function(e){
  3092. if (!this.isExpanded()) {
  3093. Ext.form.ComboBox.superclass.fireKey.call(this, e);
  3094. }
  3095. },
  3096. // private
  3097. onResize : function(w, h){
  3098. Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
  3099. if(!isNaN(w) && this.isVisible() && this.list){
  3100. this.doResize(w);
  3101. }else{
  3102. this.bufferSize = w;
  3103. }
  3104. },
  3105. doResize: function(w){
  3106. if(!Ext.isDefined(this.listWidth)){
  3107. var lw = Math.max(w, this.minListWidth);
  3108. this.list.setWidth(lw);
  3109. this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
  3110. }
  3111. },
  3112. // private
  3113. onEnable : function(){
  3114. Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
  3115. if(this.hiddenField){
  3116. this.hiddenField.disabled = false;
  3117. }
  3118. },
  3119. // private
  3120. onDisable : function(){
  3121. Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
  3122. if(this.hiddenField){
  3123. this.hiddenField.disabled = true;
  3124. }
  3125. },
  3126. // private
  3127. onBeforeLoad : function(){
  3128. if(!this.hasFocus){
  3129. return;
  3130. }
  3131. this.innerList.update(this.loadingText ?
  3132. '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
  3133. this.restrictHeight();
  3134. this.selectedIndex = -1;
  3135. },
  3136. // private
  3137. onLoad : function(){
  3138. if(!this.hasFocus){
  3139. return;
  3140. }
  3141. if(this.store.getCount() > 0 || this.listEmptyText){
  3142. this.expand();
  3143. this.restrictHeight();
  3144. if(this.lastQuery == this.allQuery){
  3145. if(this.editable){
  3146. this.el.dom.select();
  3147. }
  3148. if(this.autoSelect !== false && !this.selectByValue(this.value, true)){
  3149. this.select(0, true);
  3150. }
  3151. }else{
  3152. if(this.autoSelect !== false){
  3153. this.selectNext();
  3154. }
  3155. if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
  3156. this.taTask.delay(this.typeAheadDelay);
  3157. }
  3158. }
  3159. }else{
  3160. this.collapse();
  3161. }
  3162. },
  3163. // private
  3164. onTypeAhead : function(){
  3165. if(this.store.getCount() > 0){
  3166. var r = this.store.getAt(0);
  3167. var newValue = r.data[this.displayField];
  3168. var len = newValue.length;
  3169. var selStart = this.getRawValue().length;
  3170. if(selStart != len){
  3171. this.setRawValue(newValue);
  3172. this.selectText(selStart, newValue.length);
  3173. }
  3174. }
  3175. },
  3176. // private
  3177. assertValue : function(){
  3178. var val = this.getRawValue(),
  3179. rec;
  3180. if(this.valueField && Ext.isDefined(this.value)){
  3181. rec = this.findRecord(this.valueField, this.value);
  3182. }
  3183. if(!rec || rec.get(this.displayField) != val){
  3184. rec = this.findRecord(this.displayField, val);
  3185. }
  3186. if(!rec && this.forceSelection){
  3187. if(val.length > 0 && val != this.emptyText){
  3188. this.el.dom.value = Ext.value(this.lastSelectionText, '');
  3189. this.applyEmptyText();
  3190. }else{
  3191. this.clearValue();
  3192. }
  3193. }else{
  3194. if(rec && this.valueField){
  3195. // onSelect may have already set the value and by doing so
  3196. // set the display field properly. Let's not wipe out the
  3197. // valueField here by just sending the displayField.
  3198. if (this.value == val){
  3199. return;
  3200. }
  3201. val = rec.get(this.valueField || this.displayField);
  3202. }
  3203. this.setValue(val);
  3204. }
  3205. },
  3206. // private
  3207. onSelect : function(record, index){
  3208. if(this.fireEvent('beforeselect', this, record, index) !== false){
  3209. this.setValue(record.data[this.valueField || this.displayField]);
  3210. this.collapse();
  3211. this.fireEvent('select', this, record, index);
  3212. }
  3213. },
  3214. // inherit docs
  3215. getName: function(){
  3216. var hf = this.hiddenField;
  3217. return hf && hf.name ? hf.name : this.hiddenName || Ext.form.ComboBox.superclass.getName.call(this);
  3218. },
  3219. /**
  3220. * Returns the currently selected field value or empty string if no value is set.
  3221. * @return {String} value The selected value
  3222. */
  3223. getValue : function(){
  3224. if(this.valueField){
  3225. return Ext.isDefined(this.value) ? this.value : '';
  3226. }else{
  3227. return Ext.form.ComboBox.superclass.getValue.call(this);
  3228. }
  3229. },
  3230. /**
  3231. * Clears any text/value currently set in the field
  3232. */
  3233. clearValue : function(){
  3234. if(this.hiddenField){
  3235. this.hiddenField.value = '';
  3236. }
  3237. this.setRawValue('');
  3238. this.lastSelectionText = '';
  3239. this.applyEmptyText();
  3240. this.value = '';
  3241. },
  3242. /**
  3243. * Sets the specified value into the field. If the value finds a match, the corresponding record text
  3244. * will be displayed in the field. If the value does not match the data value of an existing item,
  3245. * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
  3246. * Otherwise the field will be blank (although the value will still be set).
  3247. * @param {String} value The value to match
  3248. * @return {Ext.form.Field} this
  3249. */
  3250. setValue : function(v){
  3251. var text = v;
  3252. if(this.valueField){
  3253. var r = this.findRecord(this.valueField, v);
  3254. if(r){
  3255. text = r.data[this.displayField];
  3256. }else if(Ext.isDefined(this.valueNotFoundText)){
  3257. text = this.valueNotFoundText;
  3258. }
  3259. }
  3260. this.lastSelectionText = text;
  3261. if(this.hiddenField){
  3262. this.hiddenField.value = Ext.value(v, '');
  3263. }
  3264. Ext.form.ComboBox.superclass.setValue.call(this, text);
  3265. this.value = v;
  3266. return this;
  3267. },
  3268. // private
  3269. findRecord : function(prop, value){
  3270. var record;
  3271. if(this.store.getCount() > 0){
  3272. this.store.each(function(r){
  3273. if(r.data[prop] == value){
  3274. record = r;
  3275. return false;
  3276. }
  3277. });
  3278. }
  3279. return record;
  3280. },
  3281. // private
  3282. onViewMove : function(e, t){
  3283. this.inKeyMode = false;
  3284. },
  3285. // private
  3286. onViewOver : function(e, t){
  3287. if(this.inKeyMode){ // prevent key nav and mouse over conflicts
  3288. return;
  3289. }
  3290. var item = this.view.findItemFromChild(t);
  3291. if(item){
  3292. var index = this.view.indexOf(item);
  3293. this.select(index, false);
  3294. }
  3295. },
  3296. // private
  3297. onViewClick : function(doFocus){
  3298. var index = this.view.getSelectedIndexes()[0],
  3299. s = this.store,
  3300. r = s.getAt(index);
  3301. if(r){
  3302. this.onSelect(r, index);
  3303. }else {
  3304. this.collapse();
  3305. }
  3306. if(doFocus !== false){
  3307. this.el.focus();
  3308. }
  3309. },
  3310. // private
  3311. restrictHeight : function(){
  3312. this.innerList.dom.style.height = '';
  3313. var inner = this.innerList.dom,
  3314. pad = this.list.getFrameWidth('tb') + (this.resizable ? this.handleHeight : 0) + this.assetHeight,
  3315. h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight),
  3316. ha = this.getPosition()[1]-Ext.getBody().getScroll().top,
  3317. hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height,
  3318. space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5;
  3319. h = Math.min(h, space, this.maxHeight);
  3320. this.innerList.setHeight(h);
  3321. this.list.beginUpdate();
  3322. this.list.setHeight(h+pad);
  3323. this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
  3324. this.list.endUpdate();
  3325. },
  3326. /**
  3327. * Returns true if the dropdown list is expanded, else false.
  3328. */
  3329. isExpanded : function(){
  3330. return this.list && this.list.isVisible();
  3331. },
  3332. /**
  3333. * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
  3334. * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
  3335. * @param {String} value The data value of the item to select
  3336. * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
  3337. * selected item if it is not currently in view (defaults to true)
  3338. * @return {Boolean} True if the value matched an item in the list, else false
  3339. */
  3340. selectByValue : function(v, scrollIntoView){
  3341. if(!Ext.isEmpty(v, true)){
  3342. var r = this.findRecord(this.valueField || this.displayField, v);
  3343. if(r){
  3344. this.select(this.store.indexOf(r), scrollIntoView);
  3345. return true;
  3346. }
  3347. }
  3348. return false;
  3349. },
  3350. /**
  3351. * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
  3352. * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
  3353. * @param {Number} index The zero-based index of the list item to select
  3354. * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
  3355. * selected item if it is not currently in view (defaults to true)
  3356. */
  3357. select : function(index, scrollIntoView){
  3358. this.selectedIndex = index;
  3359. this.view.select(index);
  3360. if(scrollIntoView !== false){
  3361. var el = this.view.getNode(index);
  3362. if(el){
  3363. this.innerList.scrollChildIntoView(el, false);
  3364. }
  3365. }
  3366. },
  3367. // private
  3368. selectNext : function(){
  3369. var ct = this.store.getCount();
  3370. if(ct > 0){
  3371. if(this.selectedIndex == -1){
  3372. this.select(0);
  3373. }else if(this.selectedIndex < ct-1){
  3374. this.select(this.selectedIndex+1);
  3375. }
  3376. }
  3377. },
  3378. // private
  3379. selectPrev : function(){
  3380. var ct = this.store.getCount();
  3381. if(ct > 0){
  3382. if(this.selectedIndex == -1){
  3383. this.select(0);
  3384. }else if(this.selectedIndex !== 0){
  3385. this.select(this.selectedIndex-1);
  3386. }
  3387. }
  3388. },
  3389. // private
  3390. onKeyUp : function(e){
  3391. var k = e.getKey();
  3392. if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
  3393. this.lastKey = k;
  3394. this.dqTask.delay(this.queryDelay);
  3395. }
  3396. Ext.form.ComboBox.superclass.onKeyUp.call(this, e);
  3397. },
  3398. // private
  3399. validateBlur : function(){
  3400. return !this.list || !this.list.isVisible();
  3401. },
  3402. // private
  3403. initQuery : function(){
  3404. this.doQuery(this.getRawValue());
  3405. },
  3406. // private
  3407. beforeBlur : function(){
  3408. this.assertValue();
  3409. },
  3410. // private
  3411. postBlur : function(){
  3412. Ext.form.ComboBox.superclass.postBlur.call(this);
  3413. this.collapse();
  3414. this.inKeyMode = false;
  3415. },
  3416. /**
  3417. * Execute a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
  3418. * query allowing the query action to be canceled if needed.
  3419. * @param {String} query The SQL query to execute
  3420. * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
  3421. * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
  3422. * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
  3423. */
  3424. doQuery : function(q, forceAll){
  3425. q = Ext.isEmpty(q) ? '' : q;
  3426. var qe = {
  3427. query: q,
  3428. forceAll: forceAll,
  3429. combo: this,
  3430. cancel:false
  3431. };
  3432. if(this.fireEvent('beforequery', qe)===false || qe.cancel){
  3433. return false;
  3434. }
  3435. q = qe.query;
  3436. forceAll = qe.forceAll;
  3437. if(forceAll === true || (q.length >= this.minChars)){
  3438. if(this.lastQuery !== q){
  3439. this.lastQuery = q;
  3440. if(this.mode == 'local'){
  3441. this.selectedIndex = -1;
  3442. if(forceAll){
  3443. this.store.clearFilter();
  3444. }else{
  3445. this.store.filter(this.displayField, q);
  3446. }
  3447. this.onLoad();
  3448. }else{
  3449. this.store.baseParams[this.queryParam] = q;
  3450. this.store.load({
  3451. params: this.getParams(q)
  3452. });
  3453. this.expand();
  3454. }
  3455. }else{
  3456. this.selectedIndex = -1;
  3457. this.onLoad();
  3458. }
  3459. }
  3460. },
  3461. // private
  3462. getParams : function(q){
  3463. var params = {},
  3464. paramNames = this.store.paramNames;
  3465. if(this.pageSize){
  3466. params[paramNames.start] = 0;
  3467. params[paramNames.limit] = this.pageSize;
  3468. }
  3469. return params;
  3470. },
  3471. /**
  3472. * Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
  3473. */
  3474. collapse : function(){
  3475. if(!this.isExpanded()){
  3476. return;
  3477. }
  3478. this.list.hide();
  3479. Ext.getDoc().un('mousewheel', this.collapseIf, this);
  3480. Ext.getDoc().un('mousedown', this.collapseIf, this);
  3481. this.fireEvent('collapse', this);
  3482. },
  3483. // private
  3484. collapseIf : function(e){
  3485. if(!this.isDestroyed && !e.within(this.wrap) && !e.within(this.list)){
  3486. this.collapse();
  3487. }
  3488. },
  3489. /**
  3490. * Expands the dropdown list if it is currently hidden. Fires the {@link #expand} event on completion.
  3491. */
  3492. expand : function(){
  3493. if(this.isExpanded() || !this.hasFocus){
  3494. return;
  3495. }
  3496. if(this.title || this.pageSize){
  3497. this.assetHeight = 0;
  3498. if(this.title){
  3499. this.assetHeight += this.header.getHeight();
  3500. }
  3501. if(this.pageSize){
  3502. this.assetHeight += this.footer.getHeight();
  3503. }
  3504. }
  3505. if(this.bufferSize){
  3506. this.doResize(this.bufferSize);
  3507. delete this.bufferSize;
  3508. }
  3509. this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
  3510. // zindex can change, re-check it and set it if necessary
  3511. this.list.setZIndex(this.getZIndex());
  3512. this.list.show();
  3513. if(Ext.isGecko2){
  3514. this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
  3515. }
  3516. this.mon(Ext.getDoc(), {
  3517. scope: this,
  3518. mousewheel: this.collapseIf,
  3519. mousedown: this.collapseIf
  3520. });
  3521. this.fireEvent('expand', this);
  3522. },
  3523. /**
  3524. * @method onTriggerClick
  3525. * @hide
  3526. */
  3527. // private
  3528. // Implements the default empty TriggerField.onTriggerClick function
  3529. onTriggerClick : function(){
  3530. if(this.readOnly || this.disabled){
  3531. return;
  3532. }
  3533. if(this.isExpanded()){
  3534. this.collapse();
  3535. this.el.focus();
  3536. }else {
  3537. this.onFocus({});
  3538. if(this.triggerAction == 'all') {
  3539. this.doQuery(this.allQuery, true);
  3540. } else {
  3541. this.doQuery(this.getRawValue());
  3542. }
  3543. this.el.focus();
  3544. }
  3545. }
  3546. /**
  3547. * @hide
  3548. * @method autoSize
  3549. */
  3550. /**
  3551. * @cfg {Boolean} grow @hide
  3552. */
  3553. /**
  3554. * @cfg {Number} growMin @hide
  3555. */
  3556. /**
  3557. * @cfg {Number} growMax @hide
  3558. */
  3559. });
  3560. Ext.reg('combo', Ext.form.ComboBox);
  3561. /**
  3562. * @class Ext.form.Checkbox
  3563. * @extends Ext.form.Field
  3564. * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
  3565. * @constructor
  3566. * Creates a new Checkbox
  3567. * @param {Object} config Configuration options
  3568. * @xtype checkbox
  3569. */
  3570. Ext.form.Checkbox = Ext.extend(Ext.form.Field, {
  3571. /**
  3572. * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
  3573. */
  3574. focusClass : undefined,
  3575. /**
  3576. * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to 'x-form-field')
  3577. */
  3578. fieldClass : 'x-form-field',
  3579. /**
  3580. * @cfg {Boolean} checked <tt>true</tt> if the checkbox should render initially checked (defaults to <tt>false</tt>)
  3581. */
  3582. checked : false,
  3583. /**
  3584. * @cfg {String} boxLabel The text that appears beside the checkbox
  3585. */
  3586. boxLabel: '&#160;',
  3587. /**
  3588. * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
  3589. * {tag: 'input', type: 'checkbox', autocomplete: 'off'})
  3590. */
  3591. defaultAutoCreate : { tag: 'input', type: 'checkbox', autocomplete: 'off'},
  3592. /**
  3593. * @cfg {String} inputValue The value that should go into the generated input element's value attribute
  3594. */
  3595. /**
  3596. * @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of
  3597. * handling the check event). The handler is passed the following parameters:
  3598. * <div class="mdetail-params"><ul>
  3599. * <li><b>checkbox</b> : Ext.form.Checkbox<div class="sub-desc">The Checkbox being toggled.</div></li>
  3600. * <li><b>checked</b> : Boolean<div class="sub-desc">The new checked state of the checkbox.</div></li>
  3601. * </ul></div>
  3602. */
  3603. /**
  3604. * @cfg {Object} scope An object to use as the scope ('this' reference) of the {@link #handler} function
  3605. * (defaults to this Checkbox).
  3606. */
  3607. // private
  3608. actionMode : 'wrap',
  3609. // private
  3610. initComponent : function(){
  3611. Ext.form.Checkbox.superclass.initComponent.call(this);
  3612. this.addEvents(
  3613. /**
  3614. * @event check
  3615. * Fires when the checkbox is checked or unchecked.
  3616. * @param {Ext.form.Checkbox} this This checkbox
  3617. * @param {Boolean} checked The new checked value
  3618. */
  3619. 'check'
  3620. );
  3621. },
  3622. // private
  3623. onResize : function(){
  3624. Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
  3625. if(!this.boxLabel && !this.fieldLabel){
  3626. this.el.alignTo(this.wrap, 'c-c');
  3627. }
  3628. },
  3629. // private
  3630. initEvents : function(){
  3631. Ext.form.Checkbox.superclass.initEvents.call(this);
  3632. this.mon(this.el, {
  3633. scope: this,
  3634. click: this.onClick,
  3635. change: this.onClick
  3636. });
  3637. },
  3638. /**
  3639. * @hide
  3640. * Overridden and disabled. The editor element does not support standard valid/invalid marking.
  3641. * @method
  3642. */
  3643. markInvalid : Ext.emptyFn,
  3644. /**
  3645. * @hide
  3646. * Overridden and disabled. The editor element does not support standard valid/invalid marking.
  3647. * @method
  3648. */
  3649. clearInvalid : Ext.emptyFn,
  3650. // private
  3651. onRender : function(ct, position){
  3652. Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
  3653. if(this.inputValue !== undefined){
  3654. this.el.dom.value = this.inputValue;
  3655. }
  3656. this.wrap = this.el.wrap({cls: 'x-form-check-wrap'});
  3657. if(this.boxLabel){
  3658. this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
  3659. }
  3660. if(this.checked){
  3661. this.setValue(true);
  3662. }else{
  3663. this.checked = this.el.dom.checked;
  3664. }
  3665. // Need to repaint for IE, otherwise positioning is broken
  3666. if (Ext.isIE && !Ext.isStrict) {
  3667. this.wrap.repaint();
  3668. }
  3669. this.resizeEl = this.positionEl = this.wrap;
  3670. },
  3671. // private
  3672. onDestroy : function(){
  3673. Ext.destroy(this.wrap);
  3674. Ext.form.Checkbox.superclass.onDestroy.call(this);
  3675. },
  3676. // private
  3677. initValue : function() {
  3678. this.originalValue = this.getValue();
  3679. },
  3680. /**
  3681. * Returns the checked state of the checkbox.
  3682. * @return {Boolean} True if checked, else false
  3683. */
  3684. getValue : function(){
  3685. if(this.rendered){
  3686. return this.el.dom.checked;
  3687. }
  3688. return this.checked;
  3689. },
  3690. // private
  3691. onClick : function(){
  3692. if(this.el.dom.checked != this.checked){
  3693. this.setValue(this.el.dom.checked);
  3694. }
  3695. },
  3696. /**
  3697. * Sets the checked state of the checkbox, fires the 'check' event, and calls a
  3698. * <code>{@link #handler}</code> (if configured).
  3699. * @param {Boolean/String} checked The following values will check the checkbox:
  3700. * <code>true, 'true', '1', or 'on'</code>. Any other value will uncheck the checkbox.
  3701. * @return {Ext.form.Field} this
  3702. */
  3703. setValue : function(v){
  3704. var checked = this.checked,
  3705. inputVal = this.inputValue;
  3706. this.checked = (v === true || v === 'true' || v == '1' || (inputVal ? v == inputVal : String(v).toLowerCase() == 'on'));
  3707. if(this.rendered){
  3708. this.el.dom.checked = this.checked;
  3709. this.el.dom.defaultChecked = this.checked;
  3710. }
  3711. if(checked != this.checked){
  3712. this.fireEvent('check', this, this.checked);
  3713. if(this.handler){
  3714. this.handler.call(this.scope || this, this, this.checked);
  3715. }
  3716. }
  3717. return this;
  3718. }
  3719. });
  3720. Ext.reg('checkbox', Ext.form.Checkbox);
  3721. /**
  3722. * @class Ext.form.CheckboxGroup
  3723. * @extends Ext.form.Field
  3724. * <p>A grouping container for {@link Ext.form.Checkbox} controls.</p>
  3725. * <p>Sample usage:</p>
  3726. * <pre><code>
  3727. var myCheckboxGroup = new Ext.form.CheckboxGroup({
  3728. id:'myGroup',
  3729. xtype: 'checkboxgroup',
  3730. fieldLabel: 'Single Column',
  3731. itemCls: 'x-check-group-alt',
  3732. // Put all controls in a single column with width 100%
  3733. columns: 1,
  3734. items: [
  3735. {boxLabel: 'Item 1', name: 'cb-col-1'},
  3736. {boxLabel: 'Item 2', name: 'cb-col-2', checked: true},
  3737. {boxLabel: 'Item 3', name: 'cb-col-3'}
  3738. ]
  3739. });
  3740. * </code></pre>
  3741. * @constructor
  3742. * Creates a new CheckboxGroup
  3743. * @param {Object} config Configuration options
  3744. * @xtype checkboxgroup
  3745. */
  3746. Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, {
  3747. /**
  3748. * @cfg {Array} items An Array of {@link Ext.form.Checkbox Checkbox}es or Checkbox config objects
  3749. * to arrange in the group.
  3750. */
  3751. /**
  3752. * @cfg {String/Number/Array} columns Specifies the number of columns to use when displaying grouped
  3753. * checkbox/radio controls using automatic layout. This config can take several types of values:
  3754. * <ul><li><b>'auto'</b> : <p class="sub-desc">The controls will be rendered one per column on one row and the width
  3755. * of each column will be evenly distributed based on the width of the overall field container. This is the default.</p></li>
  3756. * <li><b>Number</b> : <p class="sub-desc">If you specific a number (e.g., 3) that number of columns will be
  3757. * created and the contained controls will be automatically distributed based on the value of {@link #vertical}.</p></li>
  3758. * <li><b>Array</b> : Object<p class="sub-desc">You can also specify an array of column widths, mixing integer
  3759. * (fixed width) and float (percentage width) values as needed (e.g., [100, .25, .75]). Any integer values will
  3760. * be rendered first, then any float values will be calculated as a percentage of the remaining space. Float
  3761. * values do not have to add up to 1 (100%) although if you want the controls to take up the entire field
  3762. * container you should do so.</p></li></ul>
  3763. */
  3764. columns : 'auto',
  3765. /**
  3766. * @cfg {Boolean} vertical True to distribute contained controls across columns, completely filling each column
  3767. * top to bottom before starting on the next column. The number of controls in each column will be automatically
  3768. * calculated to keep columns as even as possible. The default value is false, so that controls will be added
  3769. * to columns one at a time, completely filling each row left to right before starting on the next row.
  3770. */
  3771. vertical : false,
  3772. /**
  3773. * @cfg {Boolean} allowBlank False to validate that at least one item in the group is checked (defaults to true).
  3774. * If no items are selected at validation time, {@link @blankText} will be used as the error text.
  3775. */
  3776. allowBlank : true,
  3777. /**
  3778. * @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails (defaults to "You must
  3779. * select at least one item in this group")
  3780. */
  3781. blankText : "You must select at least one item in this group",
  3782. // private
  3783. defaultType : 'checkbox',
  3784. // private
  3785. groupCls : 'x-form-check-group',
  3786. // private
  3787. initComponent: function(){
  3788. this.addEvents(
  3789. /**
  3790. * @event change
  3791. * Fires when the state of a child checkbox changes.
  3792. * @param {Ext.form.CheckboxGroup} this
  3793. * @param {Array} checked An array containing the checked boxes.
  3794. */
  3795. 'change'
  3796. );
  3797. this.on('change', this.validate, this);
  3798. Ext.form.CheckboxGroup.superclass.initComponent.call(this);
  3799. },
  3800. // private
  3801. onRender : function(ct, position){
  3802. if(!this.el){
  3803. var panelCfg = {
  3804. autoEl: {
  3805. id: this.id
  3806. },
  3807. cls: this.groupCls,
  3808. layout: 'column',
  3809. renderTo: ct,
  3810. bufferResize: false // Default this to false, since it doesn't really have a proper ownerCt.
  3811. };
  3812. var colCfg = {
  3813. xtype: 'container',
  3814. defaultType: this.defaultType,
  3815. layout: 'form',
  3816. defaults: {
  3817. hideLabel: true,
  3818. anchor: '100%'
  3819. }
  3820. };
  3821. if(this.items[0].items){
  3822. // The container has standard ColumnLayout configs, so pass them in directly
  3823. Ext.apply(panelCfg, {
  3824. layoutConfig: {columns: this.items.length},
  3825. defaults: this.defaults,
  3826. items: this.items
  3827. });
  3828. for(var i=0, len=this.items.length; i<len; i++){
  3829. Ext.applyIf(this.items[i], colCfg);
  3830. }
  3831. }else{
  3832. // The container has field item configs, so we have to generate the column
  3833. // panels first then move the items into the columns as needed.
  3834. var numCols, cols = [];
  3835. if(typeof this.columns == 'string'){ // 'auto' so create a col per item
  3836. this.columns = this.items.length;
  3837. }
  3838. if(!Ext.isArray(this.columns)){
  3839. var cs = [];
  3840. for(var i=0; i<this.columns; i++){
  3841. cs.push((100/this.columns)*.01); // distribute by even %
  3842. }
  3843. this.columns = cs;
  3844. }
  3845. numCols = this.columns.length;
  3846. // Generate the column configs with the correct width setting
  3847. for(var i=0; i<numCols; i++){
  3848. var cc = Ext.apply({items:[]}, colCfg);
  3849. cc[this.columns[i] <= 1 ? 'columnWidth' : 'width'] = this.columns[i];
  3850. if(this.defaults){
  3851. cc.defaults = Ext.apply(cc.defaults || {}, this.defaults);
  3852. }
  3853. cols.push(cc);
  3854. };
  3855. // Distribute the original items into the columns
  3856. if(this.vertical){
  3857. var rows = Math.ceil(this.items.length / numCols), ri = 0;
  3858. for(var i=0, len=this.items.length; i<len; i++){
  3859. if(i>0 && i%rows==0){
  3860. ri++;
  3861. }
  3862. if(this.items[i].fieldLabel){
  3863. this.items[i].hideLabel = false;
  3864. }
  3865. cols[ri].items.push(this.items[i]);
  3866. };
  3867. }else{
  3868. for(var i=0, len=this.items.length; i<len; i++){
  3869. var ci = i % numCols;
  3870. if(this.items[i].fieldLabel){
  3871. this.items[i].hideLabel = false;
  3872. }
  3873. cols[ci].items.push(this.items[i]);
  3874. };
  3875. }
  3876. Ext.apply(panelCfg, {
  3877. layoutConfig: {columns: numCols},
  3878. items: cols
  3879. });
  3880. }
  3881. this.panel = new Ext.Container(panelCfg);
  3882. this.panel.ownerCt = this;
  3883. this.el = this.panel.getEl();
  3884. if(this.forId && this.itemCls){
  3885. var l = this.el.up(this.itemCls).child('label', true);
  3886. if(l){
  3887. l.setAttribute('htmlFor', this.forId);
  3888. }
  3889. }
  3890. var fields = this.panel.findBy(function(c){
  3891. return c.isFormField;
  3892. }, this);
  3893. this.items = new Ext.util.MixedCollection();
  3894. this.items.addAll(fields);
  3895. }
  3896. Ext.form.CheckboxGroup.superclass.onRender.call(this, ct, position);
  3897. },
  3898. initValue : function(){
  3899. if(this.value){
  3900. this.setValue.apply(this, this.buffered ? this.value : [this.value]);
  3901. delete this.buffered;
  3902. delete this.value;
  3903. }
  3904. },
  3905. afterRender : function(){
  3906. Ext.form.CheckboxGroup.superclass.afterRender.call(this);
  3907. this.eachItem(function(item){
  3908. item.on('check', this.fireChecked, this);
  3909. item.inGroup = true;
  3910. });
  3911. },
  3912. // private
  3913. doLayout: function(){
  3914. //ugly method required to layout hidden items
  3915. if(this.rendered){
  3916. this.panel.forceLayout = this.ownerCt.forceLayout;
  3917. this.panel.doLayout();
  3918. }
  3919. },
  3920. // private
  3921. fireChecked: function(){
  3922. var arr = [];
  3923. this.eachItem(function(item){
  3924. if(item.checked){
  3925. arr.push(item);
  3926. }
  3927. });
  3928. this.fireEvent('change', this, arr);
  3929. },
  3930. /**
  3931. * Runs CheckboxGroup's validations and returns an array of any errors. The only error by default
  3932. * is if allowBlank is set to true and no items are checked.
  3933. * @return {Array} Array of all validation errors
  3934. */
  3935. getErrors: function() {
  3936. var errors = Ext.form.CheckboxGroup.superclass.getErrors.apply(this, arguments);
  3937. if (!this.allowBlank) {
  3938. var blank = true;
  3939. this.eachItem(function(f){
  3940. if (f.checked) {
  3941. return (blank = false);
  3942. }
  3943. });
  3944. if (blank) errors.push(this.blankText);
  3945. }
  3946. return errors;
  3947. },
  3948. // private
  3949. isDirty: function(){
  3950. //override the behaviour to check sub items.
  3951. if (this.disabled || !this.rendered) {
  3952. return false;
  3953. }
  3954. var dirty = false;
  3955. this.eachItem(function(item){
  3956. if(item.isDirty()){
  3957. dirty = true;
  3958. return false;
  3959. }
  3960. });
  3961. return dirty;
  3962. },
  3963. // private
  3964. setReadOnly : function(readOnly){
  3965. if(this.rendered){
  3966. this.eachItem(function(item){
  3967. item.setReadOnly(readOnly);
  3968. });
  3969. }
  3970. this.readOnly = readOnly;
  3971. },
  3972. // private
  3973. onDisable : function(){
  3974. this.eachItem(function(item){
  3975. item.disable();
  3976. });
  3977. },
  3978. // private
  3979. onEnable : function(){
  3980. this.eachItem(function(item){
  3981. item.enable();
  3982. });
  3983. },
  3984. // private
  3985. onResize : function(w, h){
  3986. this.panel.setSize(w, h);
  3987. this.panel.doLayout();
  3988. },
  3989. // inherit docs from Field
  3990. reset : function(){
  3991. if (this.originalValue) {
  3992. // Clear all items
  3993. this.eachItem(function(c){
  3994. if(c.setValue){
  3995. c.setValue(false);
  3996. c.originalValue = c.getValue();
  3997. }
  3998. });
  3999. // Set items stored in originalValue, ugly - set a flag to reset the originalValue
  4000. // during the horrible onSetValue. This will allow trackResetOnLoad to function.
  4001. this.resetOriginal = true;
  4002. this.setValue(this.originalValue);
  4003. delete this.resetOriginal;
  4004. } else {
  4005. this.eachItem(function(c){
  4006. if(c.reset){
  4007. c.reset();
  4008. }
  4009. });
  4010. }
  4011. // Defer the clearInvalid so if BaseForm's collection is being iterated it will be called AFTER it is complete.
  4012. // Important because reset is being called on both the group and the individual items.
  4013. (function() {
  4014. this.clearInvalid();
  4015. }).defer(50, this);
  4016. },
  4017. /**
  4018. * {@link Ext.form.Checkbox#setValue Set the value(s)} of an item or items
  4019. * in the group. Examples illustrating how this method may be called:
  4020. * <pre><code>
  4021. // call with name and value
  4022. myCheckboxGroup.setValue('cb-col-1', true);
  4023. // call with an array of boolean values
  4024. myCheckboxGroup.setValue([true, false, false]);
  4025. // call with an object literal specifying item:value pairs
  4026. myCheckboxGroup.setValue({
  4027. 'cb-col-2': false,
  4028. 'cb-col-3': true
  4029. });
  4030. // use comma separated string to set items with name to true (checked)
  4031. myCheckboxGroup.setValue('cb-col-1,cb-col-3');
  4032. * </code></pre>
  4033. * See {@link Ext.form.Checkbox#setValue} for additional information.
  4034. * @param {Mixed} id The checkbox to check, or as described by example shown.
  4035. * @param {Boolean} value (optional) The value to set the item.
  4036. * @return {Ext.form.CheckboxGroup} this
  4037. */
  4038. setValue: function(){
  4039. if(this.rendered){
  4040. this.onSetValue.apply(this, arguments);
  4041. }else{
  4042. this.buffered = true;
  4043. this.value = arguments;
  4044. }
  4045. return this;
  4046. },
  4047. /**
  4048. * @private
  4049. * Sets the values of one or more of the items within the CheckboxGroup
  4050. * @param {String|Array|Object} id Can take multiple forms. Can be optionally:
  4051. * <ul>
  4052. * <li>An ID string to be used with a second argument</li>
  4053. * <li>An array of the form ['some', 'list', 'of', 'ids', 'to', 'mark', 'checked']</li>
  4054. * <li>An array in the form [true, true, false, true, false] etc, where each item relates to the check status of
  4055. * the checkbox at the same index</li>
  4056. * <li>An object containing ids of the checkboxes as keys and check values as properties</li>
  4057. * </ul>
  4058. * @param {String} value The value to set the field to if the first argument was a string
  4059. */
  4060. onSetValue: function(id, value){
  4061. if(arguments.length == 1){
  4062. if(Ext.isArray(id)){
  4063. Ext.each(id, function(val, idx){
  4064. if (Ext.isObject(val) && val.setValue){ // array of checkbox components to be checked
  4065. val.setValue(true);
  4066. if (this.resetOriginal === true) {
  4067. val.originalValue = val.getValue();
  4068. }
  4069. } else { // an array of boolean values
  4070. var item = this.items.itemAt(idx);
  4071. if(item){
  4072. item.setValue(val);
  4073. }
  4074. }
  4075. }, this);
  4076. }else if(Ext.isObject(id)){
  4077. // set of name/value pairs
  4078. for(var i in id){
  4079. var f = this.getBox(i);
  4080. if(f){
  4081. f.setValue(id[i]);
  4082. }
  4083. }
  4084. }else{
  4085. this.setValueForItem(id);
  4086. }
  4087. }else{
  4088. var f = this.getBox(id);
  4089. if(f){
  4090. f.setValue(value);
  4091. }
  4092. }
  4093. },
  4094. // private
  4095. beforeDestroy: function(){
  4096. Ext.destroy(this.panel);
  4097. if (!this.rendered) {
  4098. Ext.destroy(this.items);
  4099. }
  4100. Ext.form.CheckboxGroup.superclass.beforeDestroy.call(this);
  4101. },
  4102. setValueForItem : function(val){
  4103. val = String(val).split(',');
  4104. this.eachItem(function(item){
  4105. if(val.indexOf(item.inputValue)> -1){
  4106. item.setValue(true);
  4107. }
  4108. });
  4109. },
  4110. // private
  4111. getBox : function(id){
  4112. var box = null;
  4113. this.eachItem(function(f){
  4114. if(id == f || f.dataIndex == id || f.id == id || f.getName() == id){
  4115. box = f;
  4116. return false;
  4117. }
  4118. });
  4119. return box;
  4120. },
  4121. /**
  4122. * Gets an array of the selected {@link Ext.form.Checkbox} in the group.
  4123. * @return {Array} An array of the selected checkboxes.
  4124. */
  4125. getValue : function(){
  4126. var out = [];
  4127. this.eachItem(function(item){
  4128. if(item.checked){
  4129. out.push(item);
  4130. }
  4131. });
  4132. return out;
  4133. },
  4134. /**
  4135. * @private
  4136. * Convenience function which passes the given function to every item in the composite
  4137. * @param {Function} fn The function to call
  4138. * @param {Object} scope Optional scope object
  4139. */
  4140. eachItem: function(fn, scope) {
  4141. if(this.items && this.items.each){
  4142. this.items.each(fn, scope || this);
  4143. }
  4144. },
  4145. /**
  4146. * @cfg {String} name
  4147. * @hide
  4148. */
  4149. /**
  4150. * @method getRawValue
  4151. * @hide
  4152. */
  4153. getRawValue : Ext.emptyFn,
  4154. /**
  4155. * @method setRawValue
  4156. * @hide
  4157. */
  4158. setRawValue : Ext.emptyFn
  4159. });
  4160. Ext.reg('checkboxgroup', Ext.form.CheckboxGroup);
  4161. /**
  4162. * @class Ext.form.CompositeField
  4163. * @extends Ext.form.Field
  4164. * Composite field allowing a number of form Fields to be rendered on the same row. The fields are rendered
  4165. * using an hbox layout internally, so all of the normal HBox layout config items are available. Example usage:
  4166. * <pre>
  4167. {
  4168. xtype: 'compositefield',
  4169. labelWidth: 120
  4170. items: [
  4171. {
  4172. xtype : 'textfield',
  4173. fieldLabel: 'Title',
  4174. width : 20
  4175. },
  4176. {
  4177. xtype : 'textfield',
  4178. fieldLabel: 'First',
  4179. flex : 1
  4180. },
  4181. {
  4182. xtype : 'textfield',
  4183. fieldLabel: 'Last',
  4184. flex : 1
  4185. }
  4186. ]
  4187. }
  4188. * </pre>
  4189. * In the example above the composite's fieldLabel will be set to 'Title, First, Last' as it groups the fieldLabels
  4190. * of each of its children. This can be overridden by setting a fieldLabel on the compositefield itself:
  4191. * <pre>
  4192. {
  4193. xtype: 'compositefield',
  4194. fieldLabel: 'Custom label',
  4195. items: [...]
  4196. }
  4197. * </pre>
  4198. * Any Ext.form.* component can be placed inside a composite field.
  4199. */
  4200. Ext.form.CompositeField = Ext.extend(Ext.form.Field, {
  4201. /**
  4202. * @property defaultMargins
  4203. * @type String
  4204. * The margins to apply by default to each field in the composite
  4205. */
  4206. defaultMargins: '0 5 0 0',
  4207. /**
  4208. * @property skipLastItemMargin
  4209. * @type Boolean
  4210. * If true, the defaultMargins are not applied to the last item in the composite field set (defaults to true)
  4211. */
  4212. skipLastItemMargin: true,
  4213. /**
  4214. * @property isComposite
  4215. * @type Boolean
  4216. * Signifies that this is a Composite field
  4217. */
  4218. isComposite: true,
  4219. /**
  4220. * @property combineErrors
  4221. * @type Boolean
  4222. * True to combine errors from the individual fields into a single error message at the CompositeField level (defaults to true)
  4223. */
  4224. combineErrors: true,
  4225. /**
  4226. * @cfg {String} labelConnector The string to use when joining segments of the built label together (defaults to ', ')
  4227. */
  4228. labelConnector: ', ',
  4229. /**
  4230. * @cfg {Object} defaults Any default properties to assign to the child fields.
  4231. */
  4232. //inherit docs
  4233. //Builds the composite field label
  4234. initComponent: function() {
  4235. var labels = [],
  4236. items = this.items,
  4237. item;
  4238. for (var i=0, j = items.length; i < j; i++) {
  4239. item = items[i];
  4240. if (!Ext.isEmpty(item.ref)){
  4241. item.ref = '../' + item.ref;
  4242. }
  4243. labels.push(item.fieldLabel);
  4244. //apply any defaults
  4245. Ext.applyIf(item, this.defaults);
  4246. //apply default margins to each item except the last
  4247. if (!(i == j - 1 && this.skipLastItemMargin)) {
  4248. Ext.applyIf(item, {margins: this.defaultMargins});
  4249. }
  4250. }
  4251. this.fieldLabel = this.fieldLabel || this.buildLabel(labels);
  4252. /**
  4253. * @property fieldErrors
  4254. * @type Ext.util.MixedCollection
  4255. * MixedCollection of current errors on the Composite's subfields. This is used internally to track when
  4256. * to show and hide error messages at the Composite level. Listeners are attached to the MixedCollection's
  4257. * add, remove and replace events to update the error icon in the UI as errors are added or removed.
  4258. */
  4259. this.fieldErrors = new Ext.util.MixedCollection(true, function(item) {
  4260. return item.field;
  4261. });
  4262. this.fieldErrors.on({
  4263. scope : this,
  4264. add : this.updateInvalidMark,
  4265. remove : this.updateInvalidMark,
  4266. replace: this.updateInvalidMark
  4267. });
  4268. Ext.form.CompositeField.superclass.initComponent.apply(this, arguments);
  4269. this.innerCt = new Ext.Container({
  4270. layout : 'hbox',
  4271. items : this.items,
  4272. cls : 'x-form-composite',
  4273. defaultMargins: '0 3 0 0',
  4274. ownerCt: this
  4275. });
  4276. this.innerCt.ownerCt = undefined;
  4277. var fields = this.innerCt.findBy(function(c) {
  4278. return c.isFormField;
  4279. }, this);
  4280. /**
  4281. * @property items
  4282. * @type Ext.util.MixedCollection
  4283. * Internal collection of all of the subfields in this Composite
  4284. */
  4285. this.items = new Ext.util.MixedCollection();
  4286. this.items.addAll(fields);
  4287. },
  4288. /**
  4289. * @private
  4290. * Creates an internal container using hbox and renders the fields to it
  4291. */
  4292. onRender: function(ct, position) {
  4293. if (!this.el) {
  4294. /**
  4295. * @property innerCt
  4296. * @type Ext.Container
  4297. * A container configured with hbox layout which is responsible for laying out the subfields
  4298. */
  4299. var innerCt = this.innerCt;
  4300. innerCt.render(ct);
  4301. this.el = innerCt.getEl();
  4302. //if we're combining subfield errors into a single message, override the markInvalid and clearInvalid
  4303. //methods of each subfield and show them at the Composite level instead
  4304. if (this.combineErrors) {
  4305. this.eachItem(function(field) {
  4306. Ext.apply(field, {
  4307. markInvalid : this.onFieldMarkInvalid.createDelegate(this, [field], 0),
  4308. clearInvalid: this.onFieldClearInvalid.createDelegate(this, [field], 0)
  4309. });
  4310. });
  4311. }
  4312. //set the label 'for' to the first item
  4313. var l = this.el.parent().parent().child('label', true);
  4314. if (l) {
  4315. l.setAttribute('for', this.items.items[0].id);
  4316. }
  4317. }
  4318. Ext.form.CompositeField.superclass.onRender.apply(this, arguments);
  4319. },
  4320. /**
  4321. * Called if combineErrors is true and a subfield's markInvalid method is called.
  4322. * By default this just adds the subfield's error to the internal fieldErrors MixedCollection
  4323. * @param {Ext.form.Field} field The field that was marked invalid
  4324. * @param {String} message The error message
  4325. */
  4326. onFieldMarkInvalid: function(field, message) {
  4327. var name = field.getName(),
  4328. error = {
  4329. field: name,
  4330. errorName: field.fieldLabel || name,
  4331. error: message
  4332. };
  4333. this.fieldErrors.replace(name, error);
  4334. field.el.addClass(field.invalidClass);
  4335. },
  4336. /**
  4337. * Called if combineErrors is true and a subfield's clearInvalid method is called.
  4338. * By default this just updates the internal fieldErrors MixedCollection.
  4339. * @param {Ext.form.Field} field The field that was marked invalid
  4340. */
  4341. onFieldClearInvalid: function(field) {
  4342. this.fieldErrors.removeKey(field.getName());
  4343. field.el.removeClass(field.invalidClass);
  4344. },
  4345. /**
  4346. * @private
  4347. * Called after a subfield is marked valid or invalid, this checks to see if any of the subfields are
  4348. * currently invalid. If any subfields are invalid it builds a combined error message marks the composite
  4349. * invalid, otherwise clearInvalid is called
  4350. */
  4351. updateInvalidMark: function() {
  4352. var ieStrict = Ext.isIE6 && Ext.isStrict;
  4353. if (this.fieldErrors.length == 0) {
  4354. this.clearInvalid();
  4355. //IE6 in strict mode has a layout bug when using 'under' as the error message target. This fixes it
  4356. if (ieStrict) {
  4357. this.clearInvalid.defer(50, this);
  4358. }
  4359. } else {
  4360. var message = this.buildCombinedErrorMessage(this.fieldErrors.items);
  4361. this.sortErrors();
  4362. this.markInvalid(message);
  4363. //IE6 in strict mode has a layout bug when using 'under' as the error message target. This fixes it
  4364. if (ieStrict) {
  4365. this.markInvalid(message);
  4366. }
  4367. }
  4368. },
  4369. /**
  4370. * Performs validation checks on each subfield and returns false if any of them fail validation.
  4371. * @return {Boolean} False if any subfield failed validation
  4372. */
  4373. validateValue: function() {
  4374. var valid = true;
  4375. this.eachItem(function(field) {
  4376. if (!field.isValid()) valid = false;
  4377. });
  4378. return valid;
  4379. },
  4380. /**
  4381. * Takes an object containing error messages for contained fields, returning a combined error
  4382. * string (defaults to just placing each item on a new line). This can be overridden to provide
  4383. * custom combined error message handling.
  4384. * @param {Array} errors Array of errors in format: [{field: 'title', error: 'some error'}]
  4385. * @return {String} The combined error message
  4386. */
  4387. buildCombinedErrorMessage: function(errors) {
  4388. var combined = [],
  4389. error;
  4390. for (var i = 0, j = errors.length; i < j; i++) {
  4391. error = errors[i];
  4392. combined.push(String.format("{0}: {1}", error.errorName, error.error));
  4393. }
  4394. return combined.join("<br />");
  4395. },
  4396. /**
  4397. * Sorts the internal fieldErrors MixedCollection by the order in which the fields are defined.
  4398. * This is called before displaying errors to ensure that the errors are presented in the expected order.
  4399. * This function can be overridden to provide a custom sorting order if needed.
  4400. */
  4401. sortErrors: function() {
  4402. var fields = this.items;
  4403. this.fieldErrors.sort("ASC", function(a, b) {
  4404. var findByName = function(key) {
  4405. return function(field) {
  4406. return field.getName() == key;
  4407. };
  4408. };
  4409. var aIndex = fields.findIndexBy(findByName(a.field)),
  4410. bIndex = fields.findIndexBy(findByName(b.field));
  4411. return aIndex < bIndex ? -1 : 1;
  4412. });
  4413. },
  4414. /**
  4415. * Resets each field in the composite to their previous value
  4416. */
  4417. reset: function() {
  4418. this.eachItem(function(item) {
  4419. item.reset();
  4420. });
  4421. // Defer the clearInvalid so if BaseForm's collection is being iterated it will be called AFTER it is complete.
  4422. // Important because reset is being called on both the group and the individual items.
  4423. (function() {
  4424. this.clearInvalid();
  4425. }).defer(50, this);
  4426. },
  4427. /**
  4428. * Calls clearInvalid on all child fields. This is a convenience function and should not often need to be called
  4429. * as fields usually take care of clearing themselves
  4430. */
  4431. clearInvalidChildren: function() {
  4432. this.eachItem(function(item) {
  4433. item.clearInvalid();
  4434. });
  4435. },
  4436. /**
  4437. * Builds a label string from an array of subfield labels.
  4438. * By default this just joins the labels together with a comma
  4439. * @param {Array} segments Array of each of the labels in the composite field's subfields
  4440. * @return {String} The built label
  4441. */
  4442. buildLabel: function(segments) {
  4443. return Ext.clean(segments).join(this.labelConnector);
  4444. },
  4445. /**
  4446. * Checks each field in the composite and returns true if any is dirty
  4447. * @return {Boolean} True if any field is dirty
  4448. */
  4449. isDirty: function(){
  4450. //override the behaviour to check sub items.
  4451. if (this.disabled || !this.rendered) {
  4452. return false;
  4453. }
  4454. var dirty = false;
  4455. this.eachItem(function(item){
  4456. if(item.isDirty()){
  4457. dirty = true;
  4458. return false;
  4459. }
  4460. });
  4461. return dirty;
  4462. },
  4463. /**
  4464. * @private
  4465. * Convenience function which passes the given function to every item in the composite
  4466. * @param {Function} fn The function to call
  4467. * @param {Object} scope Optional scope object
  4468. */
  4469. eachItem: function(fn, scope) {
  4470. if(this.items && this.items.each){
  4471. this.items.each(fn, scope || this);
  4472. }
  4473. },
  4474. /**
  4475. * @private
  4476. * Passes the resize call through to the inner panel
  4477. */
  4478. onResize: function(adjWidth, adjHeight, rawWidth, rawHeight) {
  4479. var innerCt = this.innerCt;
  4480. if (this.rendered && innerCt.rendered) {
  4481. innerCt.setSize(adjWidth, adjHeight);
  4482. }
  4483. Ext.form.CompositeField.superclass.onResize.apply(this, arguments);
  4484. },
  4485. /**
  4486. * @private
  4487. * Forces the internal container to be laid out again
  4488. */
  4489. doLayout: function(shallow, force) {
  4490. if (this.rendered) {
  4491. var innerCt = this.innerCt;
  4492. innerCt.forceLayout = this.ownerCt.forceLayout;
  4493. innerCt.doLayout(shallow, force);
  4494. }
  4495. },
  4496. /**
  4497. * @private
  4498. */
  4499. beforeDestroy: function(){
  4500. Ext.destroy(this.innerCt);
  4501. Ext.form.CompositeField.superclass.beforeDestroy.call(this);
  4502. },
  4503. //override the behaviour to check sub items.
  4504. setReadOnly : function(readOnly) {
  4505. if (readOnly == undefined) {
  4506. readOnly = true;
  4507. }
  4508. readOnly = !!readOnly;
  4509. if(this.rendered){
  4510. this.eachItem(function(item){
  4511. item.setReadOnly(readOnly);
  4512. });
  4513. }
  4514. this.readOnly = readOnly;
  4515. },
  4516. onShow : function() {
  4517. Ext.form.CompositeField.superclass.onShow.call(this);
  4518. this.doLayout();
  4519. },
  4520. //override the behaviour to check sub items.
  4521. onDisable : function(){
  4522. this.eachItem(function(item){
  4523. item.disable();
  4524. });
  4525. },
  4526. //override the behaviour to check sub items.
  4527. onEnable : function(){
  4528. this.eachItem(function(item){
  4529. item.enable();
  4530. });
  4531. }
  4532. });
  4533. Ext.reg('compositefield', Ext.form.CompositeField);/**
  4534. * @class Ext.form.Radio
  4535. * @extends Ext.form.Checkbox
  4536. * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
  4537. * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
  4538. * @constructor
  4539. * Creates a new Radio
  4540. * @param {Object} config Configuration options
  4541. * @xtype radio
  4542. */
  4543. Ext.form.Radio = Ext.extend(Ext.form.Checkbox, {
  4544. inputType: 'radio',
  4545. /**
  4546. * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
  4547. * @method
  4548. */
  4549. markInvalid : Ext.emptyFn,
  4550. /**
  4551. * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
  4552. * @method
  4553. */
  4554. clearInvalid : Ext.emptyFn,
  4555. /**
  4556. * If this radio is part of a group, it will return the selected value
  4557. * @return {String}
  4558. */
  4559. getGroupValue : function(){
  4560. var p = this.el.up('form') || Ext.getBody();
  4561. var c = p.child('input[name='+this.el.dom.name+']:checked', true);
  4562. return c ? c.value : null;
  4563. },
  4564. /**
  4565. * Sets either the checked/unchecked status of this Radio, or, if a string value
  4566. * is passed, checks a sibling Radio of the same name whose value is the value specified.
  4567. * @param value {String/Boolean} Checked value, or the value of the sibling radio button to check.
  4568. * @return {Ext.form.Field} this
  4569. */
  4570. setValue : function(v){
  4571. var checkEl,
  4572. els,
  4573. radio;
  4574. if (typeof v == 'boolean') {
  4575. Ext.form.Radio.superclass.setValue.call(this, v);
  4576. } else if (this.rendered) {
  4577. checkEl = this.getCheckEl();
  4578. radio = checkEl.child('input[name=' + this.el.dom.name + '][value=' + v + ']', true);
  4579. if(radio){
  4580. Ext.getCmp(radio.id).setValue(true);
  4581. }
  4582. }
  4583. if(this.rendered && this.checked){
  4584. checkEl = checkEl || this.getCheckEl();
  4585. els = this.getCheckEl().select('input[name=' + this.el.dom.name + ']');
  4586. els.each(function(el){
  4587. if(el.dom.id != this.id){
  4588. Ext.getCmp(el.dom.id).setValue(false);
  4589. }
  4590. }, this);
  4591. }
  4592. return this;
  4593. },
  4594. // private
  4595. getCheckEl: function(){
  4596. if(this.inGroup){
  4597. return this.el.up('.x-form-radio-group');
  4598. }
  4599. return this.el.up('form') || Ext.getBody();
  4600. }
  4601. });
  4602. Ext.reg('radio', Ext.form.Radio);
  4603. /**
  4604. * @class Ext.form.RadioGroup
  4605. * @extends Ext.form.CheckboxGroup
  4606. * A grouping container for {@link Ext.form.Radio} controls.
  4607. * @constructor
  4608. * Creates a new RadioGroup
  4609. * @param {Object} config Configuration options
  4610. * @xtype radiogroup
  4611. */
  4612. Ext.form.RadioGroup = Ext.extend(Ext.form.CheckboxGroup, {
  4613. /**
  4614. * @cfg {Array} items An Array of {@link Ext.form.Radio Radio}s or Radio config objects
  4615. * to arrange in the group.
  4616. */
  4617. /**
  4618. * @cfg {Boolean} allowBlank True to allow every item in the group to be blank (defaults to true).
  4619. * If allowBlank = false and no items are selected at validation time, {@link @blankText} will
  4620. * be used as the error text.
  4621. */
  4622. allowBlank : true,
  4623. /**
  4624. * @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails
  4625. * (defaults to 'You must select one item in this group')
  4626. */
  4627. blankText : 'You must select one item in this group',
  4628. // private
  4629. defaultType : 'radio',
  4630. // private
  4631. groupCls : 'x-form-radio-group',
  4632. /**
  4633. * @event change
  4634. * Fires when the state of a child radio changes.
  4635. * @param {Ext.form.RadioGroup} this
  4636. * @param {Ext.form.Radio} checked The checked radio
  4637. */
  4638. /**
  4639. * Gets the selected {@link Ext.form.Radio} in the group, if it exists.
  4640. * @return {Ext.form.Radio} The selected radio.
  4641. */
  4642. getValue : function(){
  4643. var out = null;
  4644. this.eachItem(function(item){
  4645. if(item.checked){
  4646. out = item;
  4647. return false;
  4648. }
  4649. });
  4650. return out;
  4651. },
  4652. /**
  4653. * Sets the checked radio in the group.
  4654. * @param {String/Ext.form.Radio} id The radio to check.
  4655. * @param {Boolean} value The value to set the radio.
  4656. * @return {Ext.form.RadioGroup} this
  4657. */
  4658. onSetValue : function(id, value){
  4659. if(arguments.length > 1){
  4660. var f = this.getBox(id);
  4661. if(f){
  4662. f.setValue(value);
  4663. if(f.checked){
  4664. this.eachItem(function(item){
  4665. if (item !== f){
  4666. item.setValue(false);
  4667. }
  4668. });
  4669. }
  4670. }
  4671. }else{
  4672. this.setValueForItem(id);
  4673. }
  4674. },
  4675. setValueForItem : function(val){
  4676. val = String(val).split(',')[0];
  4677. this.eachItem(function(item){
  4678. item.setValue(val == item.inputValue);
  4679. });
  4680. },
  4681. // private
  4682. fireChecked : function(){
  4683. if(!this.checkTask){
  4684. this.checkTask = new Ext.util.DelayedTask(this.bufferChecked, this);
  4685. }
  4686. this.checkTask.delay(10);
  4687. },
  4688. // private
  4689. bufferChecked : function(){
  4690. var out = null;
  4691. this.eachItem(function(item){
  4692. if(item.checked){
  4693. out = item;
  4694. return false;
  4695. }
  4696. });
  4697. this.fireEvent('change', this, out);
  4698. },
  4699. onDestroy : function(){
  4700. if(this.checkTask){
  4701. this.checkTask.cancel();
  4702. this.checkTask = null;
  4703. }
  4704. Ext.form.RadioGroup.superclass.onDestroy.call(this);
  4705. }
  4706. });
  4707. Ext.reg('radiogroup', Ext.form.RadioGroup);
  4708. /**
  4709. * @class Ext.form.Hidden
  4710. * @extends Ext.form.Field
  4711. * A basic hidden field for storing hidden values in forms that need to be passed in the form submit.
  4712. * @constructor
  4713. * Create a new Hidden field.
  4714. * @param {Object} config Configuration options
  4715. * @xtype hidden
  4716. */
  4717. Ext.form.Hidden = Ext.extend(Ext.form.Field, {
  4718. // private
  4719. inputType : 'hidden',
  4720. shouldLayout: false,
  4721. // private
  4722. onRender : function(){
  4723. Ext.form.Hidden.superclass.onRender.apply(this, arguments);
  4724. },
  4725. // private
  4726. initEvents : function(){
  4727. this.originalValue = this.getValue();
  4728. },
  4729. // These are all private overrides
  4730. setSize : Ext.emptyFn,
  4731. setWidth : Ext.emptyFn,
  4732. setHeight : Ext.emptyFn,
  4733. setPosition : Ext.emptyFn,
  4734. setPagePosition : Ext.emptyFn,
  4735. markInvalid : Ext.emptyFn,
  4736. clearInvalid : Ext.emptyFn
  4737. });
  4738. Ext.reg('hidden', Ext.form.Hidden);/**
  4739. * @class Ext.form.BasicForm
  4740. * @extends Ext.util.Observable
  4741. * <p>Encapsulates the DOM &lt;form> element at the heart of the {@link Ext.form.FormPanel FormPanel} class, and provides
  4742. * input field management, validation, submission, and form loading services.</p>
  4743. * <p>By default, Ext Forms are submitted through Ajax, using an instance of {@link Ext.form.Action.Submit}.
  4744. * To enable normal browser submission of an Ext Form, use the {@link #standardSubmit} config option.</p>
  4745. * <p><b><u>File Uploads</u></b></p>
  4746. * <p>{@link #fileUpload File uploads} are not performed using Ajax submission, that
  4747. * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard
  4748. * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its
  4749. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  4750. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  4751. * but removed after the return data has been gathered.</p>
  4752. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  4753. * server is using JSON to send the return object, then the
  4754. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  4755. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  4756. * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  4757. * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
  4758. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  4759. * is created containing a <tt>responseText</tt> property in order to conform to the
  4760. * requirements of event handlers and callbacks.</p>
  4761. * <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>
  4762. * and some server technologies (notably JEE) may require some custom processing in order to
  4763. * retrieve parameter names and parameter values from the packet content.</p>
  4764. * @constructor
  4765. * @param {Mixed} el The form element or its id
  4766. * @param {Object} config Configuration options
  4767. */
  4768. Ext.form.BasicForm = Ext.extend(Ext.util.Observable, {
  4769. constructor: function(el, config){
  4770. Ext.apply(this, config);
  4771. if(Ext.isString(this.paramOrder)){
  4772. this.paramOrder = this.paramOrder.split(/[\s,|]/);
  4773. }
  4774. /**
  4775. * A {@link Ext.util.MixedCollection MixedCollection} containing all the Ext.form.Fields in this form.
  4776. * @type MixedCollection
  4777. * @property items
  4778. */
  4779. this.items = new Ext.util.MixedCollection(false, function(o){
  4780. return o.getItemId();
  4781. });
  4782. this.addEvents(
  4783. /**
  4784. * @event beforeaction
  4785. * Fires before any action is performed. Return false to cancel the action.
  4786. * @param {Form} this
  4787. * @param {Action} action The {@link Ext.form.Action} to be performed
  4788. */
  4789. 'beforeaction',
  4790. /**
  4791. * @event actionfailed
  4792. * Fires when an action fails.
  4793. * @param {Form} this
  4794. * @param {Action} action The {@link Ext.form.Action} that failed
  4795. */
  4796. 'actionfailed',
  4797. /**
  4798. * @event actioncomplete
  4799. * Fires when an action is completed.
  4800. * @param {Form} this
  4801. * @param {Action} action The {@link Ext.form.Action} that completed
  4802. */
  4803. 'actioncomplete'
  4804. );
  4805. if(el){
  4806. this.initEl(el);
  4807. }
  4808. Ext.form.BasicForm.superclass.constructor.call(this);
  4809. },
  4810. /**
  4811. * @cfg {String} method
  4812. * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
  4813. */
  4814. /**
  4815. * @cfg {DataReader} reader
  4816. * An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read
  4817. * data when executing 'load' actions. This is optional as there is built-in
  4818. * support for processing JSON. For additional information on using an XMLReader
  4819. * see the example provided in examples/form/xml-form.html.
  4820. */
  4821. /**
  4822. * @cfg {DataReader} errorReader
  4823. * <p>An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to
  4824. * read field error messages returned from 'submit' actions. This is optional
  4825. * as there is built-in support for processing JSON.</p>
  4826. * <p>The Records which provide messages for the invalid Fields must use the
  4827. * Field name (or id) as the Record ID, and must contain a field called 'msg'
  4828. * which contains the error message.</p>
  4829. * <p>The errorReader does not have to be a full-blown implementation of a
  4830. * DataReader. It simply needs to implement a <tt>read(xhr)</tt> function
  4831. * which returns an Array of Records in an object with the following
  4832. * structure:</p><pre><code>
  4833. {
  4834. records: recordArray
  4835. }
  4836. </code></pre>
  4837. */
  4838. /**
  4839. * @cfg {String} url
  4840. * The URL to use for form actions if one isn't supplied in the
  4841. * <code>{@link #doAction doAction} options</code>.
  4842. */
  4843. /**
  4844. * @cfg {Boolean} fileUpload
  4845. * Set to true if this form is a file upload.
  4846. * <p>File uploads are not performed using normal 'Ajax' techniques, that is they are <b>not</b>
  4847. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  4848. * DOM <tt>&lt;form></tt> element temporarily modified to have its
  4849. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  4850. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  4851. * but removed after the return data has been gathered.</p>
  4852. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  4853. * server is using JSON to send the return object, then the
  4854. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  4855. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  4856. * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  4857. * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
  4858. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  4859. * is created containing a <tt>responseText</tt> property in order to conform to the
  4860. * requirements of event handlers and callbacks.</p>
  4861. * <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>
  4862. * and some server technologies (notably JEE) may require some custom processing in order to
  4863. * retrieve parameter names and parameter values from the packet content.</p>
  4864. */
  4865. /**
  4866. * @cfg {Object} baseParams
  4867. * <p>Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.</p>
  4868. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
  4869. */
  4870. /**
  4871. * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
  4872. */
  4873. timeout: 30,
  4874. /**
  4875. * @cfg {Object} api (Optional) If specified load and submit actions will be handled
  4876. * with {@link Ext.form.Action.DirectLoad} and {@link Ext.form.Action.DirectSubmit}.
  4877. * Methods which have been imported by Ext.Direct can be specified here to load and submit
  4878. * forms.
  4879. * Such as the following:<pre><code>
  4880. api: {
  4881. load: App.ss.MyProfile.load,
  4882. submit: App.ss.MyProfile.submit
  4883. }
  4884. </code></pre>
  4885. * <p>Load actions can use <code>{@link #paramOrder}</code> or <code>{@link #paramsAsHash}</code>
  4886. * to customize how the load method is invoked.
  4887. * Submit actions will always use a standard form submit. The formHandler configuration must
  4888. * be set on the associated server-side method which has been imported by Ext.Direct</p>
  4889. */
  4890. /**
  4891. * @cfg {Array/String} paramOrder <p>A list of params to be executed server side.
  4892. * Defaults to <tt>undefined</tt>. Only used for the <code>{@link #api}</code>
  4893. * <code>load</code> configuration.</p>
  4894. * <br><p>Specify the params in the order in which they must be executed on the
  4895. * server-side as either (1) an Array of String values, or (2) a String of params
  4896. * delimited by either whitespace, comma, or pipe. For example,
  4897. * any of the following would be acceptable:</p><pre><code>
  4898. paramOrder: ['param1','param2','param3']
  4899. paramOrder: 'param1 param2 param3'
  4900. paramOrder: 'param1,param2,param3'
  4901. paramOrder: 'param1|param2|param'
  4902. </code></pre>
  4903. */
  4904. paramOrder: undefined,
  4905. /**
  4906. * @cfg {Boolean} paramsAsHash Only used for the <code>{@link #api}</code>
  4907. * <code>load</code> configuration. Send parameters as a collection of named
  4908. * arguments (defaults to <tt>false</tt>). Providing a
  4909. * <tt>{@link #paramOrder}</tt> nullifies this configuration.
  4910. */
  4911. paramsAsHash: false,
  4912. /**
  4913. * @cfg {String} waitTitle
  4914. * The default title to show for the waiting message box (defaults to <tt>'Please Wait...'</tt>)
  4915. */
  4916. waitTitle: 'Please Wait...',
  4917. // private
  4918. activeAction : null,
  4919. /**
  4920. * @cfg {Boolean} trackResetOnLoad If set to <tt>true</tt>, {@link #reset}() resets to the last loaded
  4921. * or {@link #setValues}() data instead of when the form was first created. Defaults to <tt>false</tt>.
  4922. */
  4923. trackResetOnLoad : false,
  4924. /**
  4925. * @cfg {Boolean} standardSubmit
  4926. * <p>If set to <tt>true</tt>, standard HTML form submits are used instead
  4927. * of XHR (Ajax) style form submissions. Defaults to <tt>false</tt>.</p>
  4928. * <br><p><b>Note:</b> When using <code>standardSubmit</code>, the
  4929. * <code>options</code> to <code>{@link #submit}</code> are ignored because
  4930. * Ext's Ajax infrastracture is bypassed. To pass extra parameters (e.g.
  4931. * <code>baseParams</code> and <code>params</code>), utilize hidden fields
  4932. * to submit extra data, for example:</p>
  4933. * <pre><code>
  4934. new Ext.FormPanel({
  4935. standardSubmit: true,
  4936. baseParams: {
  4937. foo: 'bar'
  4938. },
  4939. {@link url}: 'myProcess.php',
  4940. items: [{
  4941. xtype: 'textfield',
  4942. name: 'userName'
  4943. }],
  4944. buttons: [{
  4945. text: 'Save',
  4946. handler: function(){
  4947. var fp = this.ownerCt.ownerCt,
  4948. form = fp.getForm();
  4949. if (form.isValid()) {
  4950. // check if there are baseParams and if
  4951. // hiddent items have been added already
  4952. if (fp.baseParams && !fp.paramsAdded) {
  4953. // add hidden items for all baseParams
  4954. for (i in fp.baseParams) {
  4955. fp.add({
  4956. xtype: 'hidden',
  4957. name: i,
  4958. value: fp.baseParams[i]
  4959. });
  4960. }
  4961. fp.doLayout();
  4962. // set a custom flag to prevent re-adding
  4963. fp.paramsAdded = true;
  4964. }
  4965. form.{@link #submit}();
  4966. }
  4967. }
  4968. }]
  4969. });
  4970. * </code></pre>
  4971. */
  4972. /**
  4973. * By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific
  4974. * element by passing it or its id or mask the form itself by passing in true.
  4975. * @type Mixed
  4976. * @property waitMsgTarget
  4977. */
  4978. // private
  4979. initEl : function(el){
  4980. this.el = Ext.get(el);
  4981. this.id = this.el.id || Ext.id();
  4982. if(!this.standardSubmit){
  4983. this.el.on('submit', this.onSubmit, this);
  4984. }
  4985. this.el.addClass('x-form');
  4986. },
  4987. /**
  4988. * Get the HTML form Element
  4989. * @return Ext.Element
  4990. */
  4991. getEl: function(){
  4992. return this.el;
  4993. },
  4994. // private
  4995. onSubmit : function(e){
  4996. e.stopEvent();
  4997. },
  4998. /**
  4999. * Destroys this object.
  5000. * @private
  5001. * @param {Boolean} bound true if the object is bound to a form panel. If this is the case
  5002. * the FormPanel will take care of destroying certain things, so we're just doubling up.
  5003. */
  5004. destroy: function(bound){
  5005. if(bound !== true){
  5006. this.items.each(function(f){
  5007. Ext.destroy(f);
  5008. });
  5009. Ext.destroy(this.el);
  5010. }
  5011. this.items.clear();
  5012. this.purgeListeners();
  5013. },
  5014. /**
  5015. * Returns true if client-side validation on the form is successful.
  5016. * @return Boolean
  5017. */
  5018. isValid : function(){
  5019. var valid = true;
  5020. this.items.each(function(f){
  5021. if(!f.validate()){
  5022. valid = false;
  5023. }
  5024. });
  5025. return valid;
  5026. },
  5027. /**
  5028. * <p>Returns true if any fields in this form have changed from their original values.</p>
  5029. * <p>Note that if this BasicForm was configured with {@link #trackResetOnLoad} then the
  5030. * Fields' <i>original values</i> are updated when the values are loaded by {@link #setValues}
  5031. * or {@link #loadRecord}.</p>
  5032. * @return Boolean
  5033. */
  5034. isDirty : function(){
  5035. var dirty = false;
  5036. this.items.each(function(f){
  5037. if(f.isDirty()){
  5038. dirty = true;
  5039. return false;
  5040. }
  5041. });
  5042. return dirty;
  5043. },
  5044. /**
  5045. * Performs a predefined action ({@link Ext.form.Action.Submit} or
  5046. * {@link Ext.form.Action.Load}) or a custom extension of {@link Ext.form.Action}
  5047. * to perform application-specific processing.
  5048. * @param {String/Object} actionName The name of the predefined action type,
  5049. * or instance of {@link Ext.form.Action} to perform.
  5050. * @param {Object} options (optional) The options to pass to the {@link Ext.form.Action}.
  5051. * All of the config options listed below are supported by both the
  5052. * {@link Ext.form.Action.Submit submit} and {@link Ext.form.Action.Load load}
  5053. * actions unless otherwise noted (custom actions could also accept
  5054. * other config options):<ul>
  5055. *
  5056. * <li><b>url</b> : String<div class="sub-desc">The url for the action (defaults
  5057. * to the form's {@link #url}.)</div></li>
  5058. *
  5059. * <li><b>method</b> : String<div class="sub-desc">The form method to use (defaults
  5060. * to the form's method, or POST if not defined)</div></li>
  5061. *
  5062. * <li><b>params</b> : String/Object<div class="sub-desc"><p>The params to pass
  5063. * (defaults to the form's baseParams, or none if not defined)</p>
  5064. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
  5065. *
  5066. * <li><b>headers</b> : Object<div class="sub-desc">Request headers to set for the action
  5067. * (defaults to the form's default headers)</div></li>
  5068. *
  5069. * <li><b>success</b> : Function<div class="sub-desc">The callback that will
  5070. * be invoked after a successful response (see top of
  5071. * {@link Ext.form.Action.Submit submit} and {@link Ext.form.Action.Load load}
  5072. * for a description of what constitutes a successful response).
  5073. * The function is passed the following parameters:<ul>
  5074. * <li><tt>form</tt> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
  5075. * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.
  5076. * <div class="sub-desc">The action object contains these properties of interest:<ul>
  5077. * <li><tt>{@link Ext.form.Action#response response}</tt></li>
  5078. * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>
  5079. * <li><tt>{@link Ext.form.Action#type type}</tt></li>
  5080. * </ul></div></li></ul></div></li>
  5081. *
  5082. * <li><b>failure</b> : Function<div class="sub-desc">The callback that will be invoked after a
  5083. * failed transaction attempt. The function is passed the following parameters:<ul>
  5084. * <li><tt>form</tt> : The {@link Ext.form.BasicForm} that requested the action.</li>
  5085. * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.
  5086. * <div class="sub-desc">The action object contains these properties of interest:<ul>
  5087. * <li><tt>{@link Ext.form.Action#failureType failureType}</tt></li>
  5088. * <li><tt>{@link Ext.form.Action#response response}</tt></li>
  5089. * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>
  5090. * <li><tt>{@link Ext.form.Action#type type}</tt></li>
  5091. * </ul></div></li></ul></div></li>
  5092. *
  5093. * <li><b>scope</b> : Object<div class="sub-desc">The scope in which to call the
  5094. * callback functions (The <tt>this</tt> reference for the callback functions).</div></li>
  5095. *
  5096. * <li><b>clientValidation</b> : Boolean<div class="sub-desc">Submit Action only.
  5097. * Determines whether a Form's fields are validated in a final call to
  5098. * {@link Ext.form.BasicForm#isValid isValid} prior to submission. Set to <tt>false</tt>
  5099. * to prevent this. If undefined, pre-submission field validation is performed.</div></li></ul>
  5100. *
  5101. * @return {BasicForm} this
  5102. */
  5103. doAction : function(action, options){
  5104. if(Ext.isString(action)){
  5105. action = new Ext.form.Action.ACTION_TYPES[action](this, options);
  5106. }
  5107. if(this.fireEvent('beforeaction', this, action) !== false){
  5108. this.beforeAction(action);
  5109. action.run.defer(100, action);
  5110. }
  5111. return this;
  5112. },
  5113. /**
  5114. * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Submit submit action}.
  5115. * @param {Object} options The options to pass to the action (see {@link #doAction} for details).<br>
  5116. * <p><b>Note:</b> this is ignored when using the {@link #standardSubmit} option.</p>
  5117. * <p>The following code:</p><pre><code>
  5118. myFormPanel.getForm().submit({
  5119. clientValidation: true,
  5120. url: 'updateConsignment.php',
  5121. params: {
  5122. newStatus: 'delivered'
  5123. },
  5124. success: function(form, action) {
  5125. Ext.Msg.alert('Success', action.result.msg);
  5126. },
  5127. failure: function(form, action) {
  5128. switch (action.failureType) {
  5129. case Ext.form.Action.CLIENT_INVALID:
  5130. Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
  5131. break;
  5132. case Ext.form.Action.CONNECT_FAILURE:
  5133. Ext.Msg.alert('Failure', 'Ajax communication failed');
  5134. break;
  5135. case Ext.form.Action.SERVER_INVALID:
  5136. Ext.Msg.alert('Failure', action.result.msg);
  5137. }
  5138. }
  5139. });
  5140. </code></pre>
  5141. * would process the following server response for a successful submission:<pre><code>
  5142. {
  5143. "success":true, // note this is Boolean, not string
  5144. "msg":"Consignment updated"
  5145. }
  5146. </code></pre>
  5147. * and the following server response for a failed submission:<pre><code>
  5148. {
  5149. "success":false, // note this is Boolean, not string
  5150. "msg":"You do not have permission to perform this operation"
  5151. }
  5152. </code></pre>
  5153. * @return {BasicForm} this
  5154. */
  5155. submit : function(options){
  5156. options = options || {};
  5157. if(this.standardSubmit){
  5158. var v = options.clientValidation === false || this.isValid();
  5159. if(v){
  5160. var el = this.el.dom;
  5161. if(this.url && Ext.isEmpty(el.action)){
  5162. el.action = this.url;
  5163. }
  5164. el.submit();
  5165. }
  5166. return v;
  5167. }
  5168. var submitAction = String.format('{0}submit', this.api ? 'direct' : '');
  5169. this.doAction(submitAction, options);
  5170. return this;
  5171. },
  5172. /**
  5173. * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Load load action}.
  5174. * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
  5175. * @return {BasicForm} this
  5176. */
  5177. load : function(options){
  5178. var loadAction = String.format('{0}load', this.api ? 'direct' : '');
  5179. this.doAction(loadAction, options);
  5180. return this;
  5181. },
  5182. /**
  5183. * Persists the values in this form into the passed {@link Ext.data.Record} object in a beginEdit/endEdit block.
  5184. * @param {Record} record The record to edit
  5185. * @return {BasicForm} this
  5186. */
  5187. updateRecord : function(record){
  5188. record.beginEdit();
  5189. var fs = record.fields,
  5190. field,
  5191. value;
  5192. fs.each(function(f){
  5193. field = this.findField(f.name);
  5194. if(field){
  5195. value = field.getValue();
  5196. if (typeof value != undefined && value.getGroupValue) {
  5197. value = value.getGroupValue();
  5198. } else if ( field.eachItem ) {
  5199. value = [];
  5200. field.eachItem(function(item){
  5201. value.push(item.getValue());
  5202. });
  5203. }
  5204. record.set(f.name, value);
  5205. }
  5206. }, this);
  5207. record.endEdit();
  5208. return this;
  5209. },
  5210. /**
  5211. * Loads an {@link Ext.data.Record} into this form by calling {@link #setValues} with the
  5212. * {@link Ext.data.Record#data record data}.
  5213. * See also {@link #trackResetOnLoad}.
  5214. * @param {Record} record The record to load
  5215. * @return {BasicForm} this
  5216. */
  5217. loadRecord : function(record){
  5218. this.setValues(record.data);
  5219. return this;
  5220. },
  5221. // private
  5222. beforeAction : function(action){
  5223. // Call HtmlEditor's syncValue before actions
  5224. this.items.each(function(f){
  5225. if(f.isFormField && f.syncValue){
  5226. f.syncValue();
  5227. }
  5228. });
  5229. var o = action.options;
  5230. if(o.waitMsg){
  5231. if(this.waitMsgTarget === true){
  5232. this.el.mask(o.waitMsg, 'x-mask-loading');
  5233. }else if(this.waitMsgTarget){
  5234. this.waitMsgTarget = Ext.get(this.waitMsgTarget);
  5235. this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
  5236. }else{
  5237. Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle);
  5238. }
  5239. }
  5240. },
  5241. // private
  5242. afterAction : function(action, success){
  5243. this.activeAction = null;
  5244. var o = action.options;
  5245. if(o.waitMsg){
  5246. if(this.waitMsgTarget === true){
  5247. this.el.unmask();
  5248. }else if(this.waitMsgTarget){
  5249. this.waitMsgTarget.unmask();
  5250. }else{
  5251. Ext.MessageBox.updateProgress(1);
  5252. Ext.MessageBox.hide();
  5253. }
  5254. }
  5255. if(success){
  5256. if(o.reset){
  5257. this.reset();
  5258. }
  5259. Ext.callback(o.success, o.scope, [this, action]);
  5260. this.fireEvent('actioncomplete', this, action);
  5261. }else{
  5262. Ext.callback(o.failure, o.scope, [this, action]);
  5263. this.fireEvent('actionfailed', this, action);
  5264. }
  5265. },
  5266. /**
  5267. * Find a {@link Ext.form.Field} in this form.
  5268. * @param {String} id The value to search for (specify either a {@link Ext.Component#id id},
  5269. * {@link Ext.grid.Column#dataIndex dataIndex}, {@link Ext.form.Field#getName name or hiddenName}).
  5270. * @return Field
  5271. */
  5272. findField : function(id) {
  5273. var field = this.items.get(id);
  5274. if (!Ext.isObject(field)) {
  5275. //searches for the field corresponding to the given id. Used recursively for composite fields
  5276. var findMatchingField = function(f) {
  5277. if (f.isFormField) {
  5278. if (f.dataIndex == id || f.id == id || f.getName() == id) {
  5279. field = f;
  5280. return false;
  5281. } else if (f.isComposite) {
  5282. return f.items.each(findMatchingField);
  5283. } else if (f instanceof Ext.form.CheckboxGroup && f.rendered) {
  5284. return f.eachItem(findMatchingField);
  5285. }
  5286. }
  5287. };
  5288. this.items.each(findMatchingField);
  5289. }
  5290. return field || null;
  5291. },
  5292. /**
  5293. * Mark fields in this form invalid in bulk.
  5294. * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
  5295. * @return {BasicForm} this
  5296. */
  5297. markInvalid : function(errors){
  5298. if (Ext.isArray(errors)) {
  5299. for(var i = 0, len = errors.length; i < len; i++){
  5300. var fieldError = errors[i];
  5301. var f = this.findField(fieldError.id);
  5302. if(f){
  5303. f.markInvalid(fieldError.msg);
  5304. }
  5305. }
  5306. } else {
  5307. var field, id;
  5308. for(id in errors){
  5309. if(!Ext.isFunction(errors[id]) && (field = this.findField(id))){
  5310. field.markInvalid(errors[id]);
  5311. }
  5312. }
  5313. }
  5314. return this;
  5315. },
  5316. /**
  5317. * Set values for fields in this form in bulk.
  5318. * @param {Array/Object} values Either an array in the form:<pre><code>
  5319. [{id:'clientName', value:'Fred. Olsen Lines'},
  5320. {id:'portOfLoading', value:'FXT'},
  5321. {id:'portOfDischarge', value:'OSL'} ]</code></pre>
  5322. * or an object hash of the form:<pre><code>
  5323. {
  5324. clientName: 'Fred. Olsen Lines',
  5325. portOfLoading: 'FXT',
  5326. portOfDischarge: 'OSL'
  5327. }</code></pre>
  5328. * @return {BasicForm} this
  5329. */
  5330. setValues : function(values){
  5331. if(Ext.isArray(values)){ // array of objects
  5332. for(var i = 0, len = values.length; i < len; i++){
  5333. var v = values[i];
  5334. var f = this.findField(v.id);
  5335. if(f){
  5336. f.setValue(v.value);
  5337. if(this.trackResetOnLoad){
  5338. f.originalValue = f.getValue();
  5339. }
  5340. }
  5341. }
  5342. }else{ // object hash
  5343. var field, id;
  5344. for(id in values){
  5345. if(!Ext.isFunction(values[id]) && (field = this.findField(id))){
  5346. field.setValue(values[id]);
  5347. if(this.trackResetOnLoad){
  5348. field.originalValue = field.getValue();
  5349. }
  5350. }
  5351. }
  5352. }
  5353. return this;
  5354. },
  5355. /**
  5356. * <p>Returns the fields in this form as an object with key/value pairs as they would be submitted using a standard form submit.
  5357. * If multiple fields exist with the same name they are returned as an array.</p>
  5358. * <p><b>Note:</b> The values are collected from all enabled HTML input elements within the form, <u>not</u> from
  5359. * the Ext Field objects. This means that all returned values are Strings (or Arrays of Strings) and that the
  5360. * value can potentially be the emptyText of a field.</p>
  5361. * @param {Boolean} asString (optional) Pass true to return the values as a string. (defaults to false, returning an Object)
  5362. * @return {String/Object}
  5363. */
  5364. getValues : function(asString){
  5365. var fs = Ext.lib.Ajax.serializeForm(this.el.dom);
  5366. if(asString === true){
  5367. return fs;
  5368. }
  5369. return Ext.urlDecode(fs);
  5370. },
  5371. /**
  5372. * Retrieves the fields in the form as a set of key/value pairs, using the {@link Ext.form.Field#getValue getValue()} method.
  5373. * If multiple fields exist with the same name they are returned as an array.
  5374. * @param {Boolean} dirtyOnly (optional) True to return only fields that are dirty.
  5375. * @return {Object} The values in the form
  5376. */
  5377. getFieldValues : function(dirtyOnly){
  5378. var o = {},
  5379. n,
  5380. key,
  5381. val;
  5382. this.items.each(function(f) {
  5383. if (!f.disabled && (dirtyOnly !== true || f.isDirty())) {
  5384. n = f.getName();
  5385. key = o[n];
  5386. val = f.getValue();
  5387. if(Ext.isDefined(key)){
  5388. if(Ext.isArray(key)){
  5389. o[n].push(val);
  5390. }else{
  5391. o[n] = [key, val];
  5392. }
  5393. }else{
  5394. o[n] = val;
  5395. }
  5396. }
  5397. });
  5398. return o;
  5399. },
  5400. /**
  5401. * Clears all invalid messages in this form.
  5402. * @return {BasicForm} this
  5403. */
  5404. clearInvalid : function(){
  5405. this.items.each(function(f){
  5406. f.clearInvalid();
  5407. });
  5408. return this;
  5409. },
  5410. /**
  5411. * Resets this form.
  5412. * @return {BasicForm} this
  5413. */
  5414. reset : function(){
  5415. this.items.each(function(f){
  5416. f.reset();
  5417. });
  5418. return this;
  5419. },
  5420. /**
  5421. * Add Ext.form Components to this form's Collection. This does not result in rendering of
  5422. * the passed Component, it just enables the form to validate Fields, and distribute values to
  5423. * Fields.
  5424. * <p><b>You will not usually call this function. In order to be rendered, a Field must be added
  5425. * to a {@link Ext.Container Container}, usually an {@link Ext.form.FormPanel FormPanel}.
  5426. * The FormPanel to which the field is added takes care of adding the Field to the BasicForm's
  5427. * collection.</b></p>
  5428. * @param {Field} field1
  5429. * @param {Field} field2 (optional)
  5430. * @param {Field} etc (optional)
  5431. * @return {BasicForm} this
  5432. */
  5433. add : function(){
  5434. this.items.addAll(Array.prototype.slice.call(arguments, 0));
  5435. return this;
  5436. },
  5437. /**
  5438. * Removes a field from the items collection (does NOT remove its markup).
  5439. * @param {Field} field
  5440. * @return {BasicForm} this
  5441. */
  5442. remove : function(field){
  5443. this.items.remove(field);
  5444. return this;
  5445. },
  5446. /**
  5447. * Removes all fields from the collection that have been destroyed.
  5448. */
  5449. cleanDestroyed : function() {
  5450. this.items.filterBy(function(o) { return !!o.isDestroyed; }).each(this.remove, this);
  5451. },
  5452. /**
  5453. * Iterates through the {@link Ext.form.Field Field}s which have been {@link #add add}ed to this BasicForm,
  5454. * checks them for an id attribute, and calls {@link Ext.form.Field#applyToMarkup} on the existing dom element with that id.
  5455. * @return {BasicForm} this
  5456. */
  5457. render : function(){
  5458. this.items.each(function(f){
  5459. if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
  5460. f.applyToMarkup(f.id);
  5461. }
  5462. });
  5463. return this;
  5464. },
  5465. /**
  5466. * Calls {@link Ext#apply} for all fields in this form with the passed object.
  5467. * @param {Object} values
  5468. * @return {BasicForm} this
  5469. */
  5470. applyToFields : function(o){
  5471. this.items.each(function(f){
  5472. Ext.apply(f, o);
  5473. });
  5474. return this;
  5475. },
  5476. /**
  5477. * Calls {@link Ext#applyIf} for all field in this form with the passed object.
  5478. * @param {Object} values
  5479. * @return {BasicForm} this
  5480. */
  5481. applyIfToFields : function(o){
  5482. this.items.each(function(f){
  5483. Ext.applyIf(f, o);
  5484. });
  5485. return this;
  5486. },
  5487. callFieldMethod : function(fnName, args){
  5488. args = args || [];
  5489. this.items.each(function(f){
  5490. if(Ext.isFunction(f[fnName])){
  5491. f[fnName].apply(f, args);
  5492. }
  5493. });
  5494. return this;
  5495. }
  5496. });
  5497. // back compat
  5498. Ext.BasicForm = Ext.form.BasicForm;
  5499. /**
  5500. * @class Ext.form.FormPanel
  5501. * @extends Ext.Panel
  5502. * <p>Standard form container.</p>
  5503. *
  5504. * <p><b><u>Layout</u></b></p>
  5505. * <p>By default, FormPanel is configured with <tt>layout:'form'</tt> to use an {@link Ext.layout.FormLayout}
  5506. * layout manager, which styles and renders fields and labels correctly. When nesting additional Containers
  5507. * within a FormPanel, you should ensure that any descendant Containers which host input Fields use the
  5508. * {@link Ext.layout.FormLayout} layout manager.</p>
  5509. *
  5510. * <p><b><u>BasicForm</u></b></p>
  5511. * <p>Although <b>not listed</b> as configuration options of FormPanel, the FormPanel class accepts all
  5512. * of the config options required to configure its internal {@link Ext.form.BasicForm} for:
  5513. * <div class="mdetail-params"><ul>
  5514. * <li>{@link Ext.form.BasicForm#fileUpload file uploads}</li>
  5515. * <li>functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form</li>
  5516. * </ul></div>
  5517. *
  5518. * <p><b>Note</b>: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
  5519. * the <tt><b>initialConfig</b></tt> property of the FormPanel. Applying {@link Ext.form.BasicForm BasicForm}
  5520. * configuration settings to <b><tt>this</tt></b> will <b>not</b> affect the BasicForm's configuration.</p>
  5521. *
  5522. * <p><b><u>Form Validation</u></b></p>
  5523. * <p>For information on form validation see the following:</p>
  5524. * <div class="mdetail-params"><ul>
  5525. * <li>{@link Ext.form.TextField}</li>
  5526. * <li>{@link Ext.form.VTypes}</li>
  5527. * <li>{@link Ext.form.BasicForm#doAction BasicForm.doAction <b>clientValidation</b> notes}</li>
  5528. * <li><tt>{@link Ext.form.FormPanel#monitorValid monitorValid}</tt></li>
  5529. * </ul></div>
  5530. *
  5531. * <p><b><u>Form Submission</u></b></p>
  5532. * <p>By default, Ext Forms are submitted through Ajax, using {@link Ext.form.Action}. To enable normal browser
  5533. * submission of the {@link Ext.form.BasicForm BasicForm} contained in this FormPanel, see the
  5534. * <tt><b>{@link Ext.form.BasicForm#standardSubmit standardSubmit}</b></tt> option.</p>
  5535. *
  5536. * @constructor
  5537. * @param {Object} config Configuration options
  5538. * @xtype form
  5539. */
  5540. Ext.FormPanel = Ext.extend(Ext.Panel, {
  5541. /**
  5542. * @cfg {String} formId (optional) The id of the FORM tag (defaults to an auto-generated id).
  5543. */
  5544. /**
  5545. * @cfg {Boolean} hideLabels
  5546. * <p><tt>true</tt> to hide field labels by default (sets <tt>display:none</tt>). Defaults to
  5547. * <tt>false</tt>.</p>
  5548. * <p>Also see {@link Ext.Component}.<tt>{@link Ext.Component#hideLabel hideLabel}</tt>.
  5549. */
  5550. /**
  5551. * @cfg {Number} labelPad
  5552. * The default padding in pixels for field labels (defaults to <tt>5</tt>). <tt>labelPad</tt> only
  5553. * applies if <tt>{@link #labelWidth}</tt> is also specified, otherwise it will be ignored.
  5554. */
  5555. /**
  5556. * @cfg {String} labelSeparator
  5557. * See {@link Ext.Component}.<tt>{@link Ext.Component#labelSeparator labelSeparator}</tt>
  5558. */
  5559. /**
  5560. * @cfg {Number} labelWidth The width of labels in pixels. This property cascades to child containers
  5561. * and can be overridden on any child container (e.g., a fieldset can specify a different <tt>labelWidth</tt>
  5562. * for its fields) (defaults to <tt>100</tt>).
  5563. */
  5564. /**
  5565. * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
  5566. */
  5567. /**
  5568. * @cfg {Array} buttons
  5569. * An array of {@link Ext.Button}s or {@link Ext.Button} configs used to add buttons to the footer of this FormPanel.<br>
  5570. * <p>Buttons in the footer of a FormPanel may be configured with the option <tt>formBind: true</tt>. This causes
  5571. * the form's {@link #monitorValid valid state monitor task} to enable/disable those Buttons depending on
  5572. * the form's valid/invalid state.</p>
  5573. */
  5574. /**
  5575. * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to <tt>75</tt>).
  5576. */
  5577. minButtonWidth : 75,
  5578. /**
  5579. * @cfg {String} labelAlign The label alignment value used for the <tt>text-align</tt> specification
  5580. * for the <b>container</b>. Valid values are <tt>"left</tt>", <tt>"top"</tt> or <tt>"right"</tt>
  5581. * (defaults to <tt>"left"</tt>). This property cascades to child <b>containers</b> and can be
  5582. * overridden on any child <b>container</b> (e.g., a fieldset can specify a different <tt>labelAlign</tt>
  5583. * for its fields).
  5584. */
  5585. labelAlign : 'left',
  5586. /**
  5587. * @cfg {Boolean} monitorValid If <tt>true</tt>, the form monitors its valid state <b>client-side</b> and
  5588. * regularly fires the {@link #clientvalidation} event passing that state.<br>
  5589. * <p>When monitoring valid state, the FormPanel enables/disables any of its configured
  5590. * {@link #buttons} which have been configured with <code>formBind: true</code> depending
  5591. * on whether the {@link Ext.form.BasicForm#isValid form is valid} or not. Defaults to <tt>false</tt></p>
  5592. */
  5593. monitorValid : false,
  5594. /**
  5595. * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
  5596. */
  5597. monitorPoll : 200,
  5598. /**
  5599. * @cfg {String} layout Defaults to <tt>'form'</tt>. Normally this configuration property should not be altered.
  5600. * For additional details see {@link Ext.layout.FormLayout} and {@link Ext.Container#layout Ext.Container.layout}.
  5601. */
  5602. layout : 'form',
  5603. // private
  5604. initComponent : function(){
  5605. this.form = this.createForm();
  5606. Ext.FormPanel.superclass.initComponent.call(this);
  5607. this.bodyCfg = {
  5608. tag: 'form',
  5609. cls: this.baseCls + '-body',
  5610. method : this.method || 'POST',
  5611. id : this.formId || Ext.id()
  5612. };
  5613. if(this.fileUpload) {
  5614. this.bodyCfg.enctype = 'multipart/form-data';
  5615. }
  5616. this.initItems();
  5617. this.addEvents(
  5618. /**
  5619. * @event clientvalidation
  5620. * If the monitorValid config option is true, this event fires repetitively to notify of valid state
  5621. * @param {Ext.form.FormPanel} this
  5622. * @param {Boolean} valid true if the form has passed client-side validation
  5623. */
  5624. 'clientvalidation'
  5625. );
  5626. this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']);
  5627. },
  5628. // private
  5629. createForm : function(){
  5630. var config = Ext.applyIf({listeners: {}}, this.initialConfig);
  5631. return new Ext.form.BasicForm(null, config);
  5632. },
  5633. // private
  5634. initFields : function(){
  5635. var f = this.form;
  5636. var formPanel = this;
  5637. var fn = function(c){
  5638. if(formPanel.isField(c)){
  5639. f.add(c);
  5640. }else if(c.findBy && c != formPanel){
  5641. formPanel.applySettings(c);
  5642. //each check required for check/radio groups.
  5643. if(c.items && c.items.each){
  5644. c.items.each(fn, this);
  5645. }
  5646. }
  5647. };
  5648. this.items.each(fn, this);
  5649. },
  5650. // private
  5651. applySettings: function(c){
  5652. var ct = c.ownerCt;
  5653. Ext.applyIf(c, {
  5654. labelAlign: ct.labelAlign,
  5655. labelWidth: ct.labelWidth,
  5656. itemCls: ct.itemCls
  5657. });
  5658. },
  5659. // private
  5660. getLayoutTarget : function(){
  5661. return this.form.el;
  5662. },
  5663. /**
  5664. * Provides access to the {@link Ext.form.BasicForm Form} which this Panel contains.
  5665. * @return {Ext.form.BasicForm} The {@link Ext.form.BasicForm Form} which this Panel contains.
  5666. */
  5667. getForm : function(){
  5668. return this.form;
  5669. },
  5670. // private
  5671. onRender : function(ct, position){
  5672. this.initFields();
  5673. Ext.FormPanel.superclass.onRender.call(this, ct, position);
  5674. this.form.initEl(this.body);
  5675. },
  5676. // private
  5677. beforeDestroy : function(){
  5678. this.stopMonitoring();
  5679. this.form.destroy(true);
  5680. Ext.FormPanel.superclass.beforeDestroy.call(this);
  5681. },
  5682. // Determine if a Component is usable as a form Field.
  5683. isField : function(c) {
  5684. return !!c.setValue && !!c.getValue && !!c.markInvalid && !!c.clearInvalid;
  5685. },
  5686. // private
  5687. initEvents : function(){
  5688. Ext.FormPanel.superclass.initEvents.call(this);
  5689. // Listeners are required here to catch bubbling events from children.
  5690. this.on({
  5691. scope: this,
  5692. add: this.onAddEvent,
  5693. remove: this.onRemoveEvent
  5694. });
  5695. if(this.monitorValid){ // initialize after render
  5696. this.startMonitoring();
  5697. }
  5698. },
  5699. // private
  5700. onAdd: function(c){
  5701. Ext.FormPanel.superclass.onAdd.call(this, c);
  5702. this.processAdd(c);
  5703. },
  5704. // private
  5705. onAddEvent: function(ct, c){
  5706. if(ct !== this){
  5707. this.processAdd(c);
  5708. }
  5709. },
  5710. // private
  5711. processAdd : function(c){
  5712. // If a single form Field, add it
  5713. if(this.isField(c)){
  5714. this.form.add(c);
  5715. // If a Container, add any Fields it might contain
  5716. }else if(c.findBy){
  5717. this.applySettings(c);
  5718. this.form.add.apply(this.form, c.findBy(this.isField));
  5719. }
  5720. },
  5721. // private
  5722. onRemove: function(c){
  5723. Ext.FormPanel.superclass.onRemove.call(this, c);
  5724. this.processRemove(c);
  5725. },
  5726. onRemoveEvent: function(ct, c){
  5727. if(ct !== this){
  5728. this.processRemove(c);
  5729. }
  5730. },
  5731. // private
  5732. processRemove: function(c){
  5733. if(!this.destroying){
  5734. // If a single form Field, remove it
  5735. if(this.isField(c)){
  5736. this.form.remove(c);
  5737. // If a Container, its already destroyed by the time it gets here. Remove any references to destroyed fields.
  5738. }else if (c.findBy){
  5739. Ext.each(c.findBy(this.isField), this.form.remove, this.form);
  5740. /*
  5741. * This isn't the most efficient way of getting rid of the items, however it's the most
  5742. * correct, which in this case is most important.
  5743. */
  5744. this.form.cleanDestroyed();
  5745. }
  5746. }
  5747. },
  5748. /**
  5749. * Starts monitoring of the valid state of this form. Usually this is done by passing the config
  5750. * option "monitorValid"
  5751. */
  5752. startMonitoring : function(){
  5753. if(!this.validTask){
  5754. this.validTask = new Ext.util.TaskRunner();
  5755. this.validTask.start({
  5756. run : this.bindHandler,
  5757. interval : this.monitorPoll || 200,
  5758. scope: this
  5759. });
  5760. }
  5761. },
  5762. /**
  5763. * Stops monitoring of the valid state of this form
  5764. */
  5765. stopMonitoring : function(){
  5766. if(this.validTask){
  5767. this.validTask.stopAll();
  5768. this.validTask = null;
  5769. }
  5770. },
  5771. /**
  5772. * This is a proxy for the underlying BasicForm's {@link Ext.form.BasicForm#load} call.
  5773. * @param {Object} options The options to pass to the action (see {@link Ext.form.BasicForm#doAction} for details)
  5774. */
  5775. load : function(){
  5776. this.form.load.apply(this.form, arguments);
  5777. },
  5778. // private
  5779. onDisable : function(){
  5780. Ext.FormPanel.superclass.onDisable.call(this);
  5781. if(this.form){
  5782. this.form.items.each(function(){
  5783. this.disable();
  5784. });
  5785. }
  5786. },
  5787. // private
  5788. onEnable : function(){
  5789. Ext.FormPanel.superclass.onEnable.call(this);
  5790. if(this.form){
  5791. this.form.items.each(function(){
  5792. this.enable();
  5793. });
  5794. }
  5795. },
  5796. // private
  5797. bindHandler : function(){
  5798. var valid = true;
  5799. this.form.items.each(function(f){
  5800. if(!f.isValid(true)){
  5801. valid = false;
  5802. return false;
  5803. }
  5804. });
  5805. if(this.fbar){
  5806. var fitems = this.fbar.items.items;
  5807. for(var i = 0, len = fitems.length; i < len; i++){
  5808. var btn = fitems[i];
  5809. if(btn.formBind === true && btn.disabled === valid){
  5810. btn.setDisabled(!valid);
  5811. }
  5812. }
  5813. }
  5814. this.fireEvent('clientvalidation', this, valid);
  5815. }
  5816. });
  5817. Ext.reg('form', Ext.FormPanel);
  5818. Ext.form.FormPanel = Ext.FormPanel;
  5819. /**
  5820. * @class Ext.form.FieldSet
  5821. * @extends Ext.Panel
  5822. * Standard container used for grouping items within a {@link Ext.form.FormPanel form}.
  5823. * <pre><code>
  5824. var form = new Ext.FormPanel({
  5825. title: 'Simple Form with FieldSets',
  5826. labelWidth: 75, // label settings here cascade unless overridden
  5827. url: 'save-form.php',
  5828. frame:true,
  5829. bodyStyle:'padding:5px 5px 0',
  5830. width: 700,
  5831. renderTo: document.body,
  5832. layout:'column', // arrange items in columns
  5833. defaults: { // defaults applied to items
  5834. layout: 'form',
  5835. border: false,
  5836. bodyStyle: 'padding:4px'
  5837. },
  5838. items: [{
  5839. // Fieldset in Column 1
  5840. xtype:'fieldset',
  5841. columnWidth: 0.5,
  5842. title: 'Fieldset 1',
  5843. collapsible: true,
  5844. autoHeight:true,
  5845. defaults: {
  5846. anchor: '-20' // leave room for error icon
  5847. },
  5848. defaultType: 'textfield',
  5849. items :[{
  5850. fieldLabel: 'Field 1'
  5851. }, {
  5852. fieldLabel: 'Field 2'
  5853. }, {
  5854. fieldLabel: 'Field 3'
  5855. }
  5856. ]
  5857. },{
  5858. // Fieldset in Column 2 - Panel inside
  5859. xtype:'fieldset',
  5860. title: 'Show Panel', // title, header, or checkboxToggle creates fieldset header
  5861. autoHeight:true,
  5862. columnWidth: 0.5,
  5863. checkboxToggle: true,
  5864. collapsed: true, // fieldset initially collapsed
  5865. layout:'anchor',
  5866. items :[{
  5867. xtype: 'panel',
  5868. anchor: '100%',
  5869. title: 'Panel inside a fieldset',
  5870. frame: true,
  5871. height: 100
  5872. }]
  5873. }]
  5874. });
  5875. * </code></pre>
  5876. * @constructor
  5877. * @param {Object} config Configuration options
  5878. * @xtype fieldset
  5879. */
  5880. Ext.form.FieldSet = Ext.extend(Ext.Panel, {
  5881. /**
  5882. * @cfg {Mixed} checkboxToggle <tt>true</tt> to render a checkbox into the fieldset frame just
  5883. * in front of the legend to expand/collapse the fieldset when the checkbox is toggled. (defaults
  5884. * to <tt>false</tt>).
  5885. * <p>A {@link Ext.DomHelper DomHelper} element spec may also be specified to create the checkbox.
  5886. * If <tt>true</tt> is specified, the default DomHelper config object used to create the element
  5887. * is:</p><pre><code>
  5888. * {tag: 'input', type: 'checkbox', name: this.checkboxName || this.id+'-checkbox'}
  5889. * </code></pre>
  5890. */
  5891. /**
  5892. * @cfg {String} checkboxName The name to assign to the fieldset's checkbox if <tt>{@link #checkboxToggle} = true</tt>
  5893. * (defaults to <tt>'[checkbox id]-checkbox'</tt>).
  5894. */
  5895. /**
  5896. * @cfg {Boolean} collapsible
  5897. * <tt>true</tt> to make the fieldset collapsible and have the expand/collapse toggle button automatically
  5898. * rendered into the legend element, <tt>false</tt> to keep the fieldset statically sized with no collapse
  5899. * button (defaults to <tt>false</tt>). Another option is to configure <tt>{@link #checkboxToggle}</tt>.
  5900. */
  5901. /**
  5902. * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
  5903. */
  5904. /**
  5905. * @cfg {String} itemCls A css class to apply to the <tt>x-form-item</tt> of fields (see
  5906. * {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl} for details).
  5907. * This property cascades to child containers.
  5908. */
  5909. /**
  5910. * @cfg {String} baseCls The base CSS class applied to the fieldset (defaults to <tt>'x-fieldset'</tt>).
  5911. */
  5912. baseCls : 'x-fieldset',
  5913. /**
  5914. * @cfg {String} layout The {@link Ext.Container#layout} to use inside the fieldset (defaults to <tt>'form'</tt>).
  5915. */
  5916. layout : 'form',
  5917. /**
  5918. * @cfg {Boolean} animCollapse
  5919. * <tt>true</tt> to animate the transition when the panel is collapsed, <tt>false</tt> to skip the
  5920. * animation (defaults to <tt>false</tt>).
  5921. */
  5922. animCollapse : false,
  5923. // private
  5924. onRender : function(ct, position){
  5925. if(!this.el){
  5926. this.el = document.createElement('fieldset');
  5927. this.el.id = this.id;
  5928. if (this.title || this.header || this.checkboxToggle) {
  5929. this.el.appendChild(document.createElement('legend')).className = this.baseCls + '-header';
  5930. }
  5931. }
  5932. Ext.form.FieldSet.superclass.onRender.call(this, ct, position);
  5933. if(this.checkboxToggle){
  5934. var o = typeof this.checkboxToggle == 'object' ?
  5935. this.checkboxToggle :
  5936. {tag: 'input', type: 'checkbox', name: this.checkboxName || this.id+'-checkbox'};
  5937. this.checkbox = this.header.insertFirst(o);
  5938. this.checkbox.dom.checked = !this.collapsed;
  5939. this.mon(this.checkbox, 'click', this.onCheckClick, this);
  5940. }
  5941. },
  5942. // private
  5943. onCollapse : function(doAnim, animArg){
  5944. if(this.checkbox){
  5945. this.checkbox.dom.checked = false;
  5946. }
  5947. Ext.form.FieldSet.superclass.onCollapse.call(this, doAnim, animArg);
  5948. },
  5949. // private
  5950. onExpand : function(doAnim, animArg){
  5951. if(this.checkbox){
  5952. this.checkbox.dom.checked = true;
  5953. }
  5954. Ext.form.FieldSet.superclass.onExpand.call(this, doAnim, animArg);
  5955. },
  5956. /**
  5957. * This function is called by the fieldset's checkbox when it is toggled (only applies when
  5958. * checkboxToggle = true). This method should never be called externally, but can be
  5959. * overridden to provide custom behavior when the checkbox is toggled if needed.
  5960. */
  5961. onCheckClick : function(){
  5962. this[this.checkbox.dom.checked ? 'expand' : 'collapse']();
  5963. }
  5964. /**
  5965. * @cfg {String/Number} activeItem
  5966. * @hide
  5967. */
  5968. /**
  5969. * @cfg {Mixed} applyTo
  5970. * @hide
  5971. */
  5972. /**
  5973. * @cfg {Boolean} bodyBorder
  5974. * @hide
  5975. */
  5976. /**
  5977. * @cfg {Boolean} border
  5978. * @hide
  5979. */
  5980. /**
  5981. * @cfg {Boolean/Number} bufferResize
  5982. * @hide
  5983. */
  5984. /**
  5985. * @cfg {Boolean} collapseFirst
  5986. * @hide
  5987. */
  5988. /**
  5989. * @cfg {String} defaultType
  5990. * @hide
  5991. */
  5992. /**
  5993. * @cfg {String} disabledClass
  5994. * @hide
  5995. */
  5996. /**
  5997. * @cfg {String} elements
  5998. * @hide
  5999. */
  6000. /**
  6001. * @cfg {Boolean} floating
  6002. * @hide
  6003. */
  6004. /**
  6005. * @cfg {Boolean} footer
  6006. * @hide
  6007. */
  6008. /**
  6009. * @cfg {Boolean} frame
  6010. * @hide
  6011. */
  6012. /**
  6013. * @cfg {Boolean} header
  6014. * @hide
  6015. */
  6016. /**
  6017. * @cfg {Boolean} headerAsText
  6018. * @hide
  6019. */
  6020. /**
  6021. * @cfg {Boolean} hideCollapseTool
  6022. * @hide
  6023. */
  6024. /**
  6025. * @cfg {String} iconCls
  6026. * @hide
  6027. */
  6028. /**
  6029. * @cfg {Boolean/String} shadow
  6030. * @hide
  6031. */
  6032. /**
  6033. * @cfg {Number} shadowOffset
  6034. * @hide
  6035. */
  6036. /**
  6037. * @cfg {Boolean} shim
  6038. * @hide
  6039. */
  6040. /**
  6041. * @cfg {Object/Array} tbar
  6042. * @hide
  6043. */
  6044. /**
  6045. * @cfg {Array} tools
  6046. * @hide
  6047. */
  6048. /**
  6049. * @cfg {Ext.Template/Ext.XTemplate} toolTemplate
  6050. * @hide
  6051. */
  6052. /**
  6053. * @cfg {String} xtype
  6054. * @hide
  6055. */
  6056. /**
  6057. * @property header
  6058. * @hide
  6059. */
  6060. /**
  6061. * @property footer
  6062. * @hide
  6063. */
  6064. /**
  6065. * @method focus
  6066. * @hide
  6067. */
  6068. /**
  6069. * @method getBottomToolbar
  6070. * @hide
  6071. */
  6072. /**
  6073. * @method getTopToolbar
  6074. * @hide
  6075. */
  6076. /**
  6077. * @method setIconClass
  6078. * @hide
  6079. */
  6080. /**
  6081. * @event activate
  6082. * @hide
  6083. */
  6084. /**
  6085. * @event beforeclose
  6086. * @hide
  6087. */
  6088. /**
  6089. * @event bodyresize
  6090. * @hide
  6091. */
  6092. /**
  6093. * @event close
  6094. * @hide
  6095. */
  6096. /**
  6097. * @event deactivate
  6098. * @hide
  6099. */
  6100. });
  6101. Ext.reg('fieldset', Ext.form.FieldSet);/**
  6102. * @class Ext.form.HtmlEditor
  6103. * @extends Ext.form.Field
  6104. * Provides a lightweight HTML Editor component. Some toolbar features are not supported by Safari and will be
  6105. * automatically hidden when needed. These are noted in the config options where appropriate.
  6106. * <br><br>The editor's toolbar buttons have tooltips defined in the {@link #buttonTips} property, but they are not
  6107. * enabled by default unless the global {@link Ext.QuickTips} singleton is {@link Ext.QuickTips#init initialized}.
  6108. * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
  6109. * supported by this editor.</b>
  6110. * <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
  6111. * any element that has display set to 'none' can cause problems in Safari and Firefox due to their default iframe reloading bugs.
  6112. * <br><br>Example usage:
  6113. * <pre><code>
  6114. // Simple example rendered with default options:
  6115. Ext.QuickTips.init(); // enable tooltips
  6116. new Ext.form.HtmlEditor({
  6117. renderTo: Ext.getBody(),
  6118. width: 800,
  6119. height: 300
  6120. });
  6121. // Passed via xtype into a container and with custom options:
  6122. Ext.QuickTips.init(); // enable tooltips
  6123. new Ext.Panel({
  6124. title: 'HTML Editor',
  6125. renderTo: Ext.getBody(),
  6126. width: 600,
  6127. height: 300,
  6128. frame: true,
  6129. layout: 'fit',
  6130. items: {
  6131. xtype: 'htmleditor',
  6132. enableColors: false,
  6133. enableAlignments: false
  6134. }
  6135. });
  6136. </code></pre>
  6137. * @constructor
  6138. * Create a new HtmlEditor
  6139. * @param {Object} config
  6140. * @xtype htmleditor
  6141. */
  6142. Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, {
  6143. /**
  6144. * @cfg {Boolean} enableFormat Enable the bold, italic and underline buttons (defaults to true)
  6145. */
  6146. enableFormat : true,
  6147. /**
  6148. * @cfg {Boolean} enableFontSize Enable the increase/decrease font size buttons (defaults to true)
  6149. */
  6150. enableFontSize : true,
  6151. /**
  6152. * @cfg {Boolean} enableColors Enable the fore/highlight color buttons (defaults to true)
  6153. */
  6154. enableColors : true,
  6155. /**
  6156. * @cfg {Boolean} enableAlignments Enable the left, center, right alignment buttons (defaults to true)
  6157. */
  6158. enableAlignments : true,
  6159. /**
  6160. * @cfg {Boolean} enableLists Enable the bullet and numbered list buttons. Not available in Safari. (defaults to true)
  6161. */
  6162. enableLists : true,
  6163. /**
  6164. * @cfg {Boolean} enableSourceEdit Enable the switch to source edit button. Not available in Safari. (defaults to true)
  6165. */
  6166. enableSourceEdit : true,
  6167. /**
  6168. * @cfg {Boolean} enableLinks Enable the create link button. Not available in Safari. (defaults to true)
  6169. */
  6170. enableLinks : true,
  6171. /**
  6172. * @cfg {Boolean} enableFont Enable font selection. Not available in Safari. (defaults to true)
  6173. */
  6174. enableFont : true,
  6175. /**
  6176. * @cfg {String} createLinkText The default text for the create link prompt
  6177. */
  6178. createLinkText : 'Please enter the URL for the link:',
  6179. /**
  6180. * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
  6181. */
  6182. defaultLinkValue : 'http:/'+'/',
  6183. /**
  6184. * @cfg {Array} fontFamilies An array of available font families
  6185. */
  6186. fontFamilies : [
  6187. 'Arial',
  6188. 'Courier New',
  6189. 'Tahoma',
  6190. 'Times New Roman',
  6191. 'Verdana'
  6192. ],
  6193. defaultFont: 'tahoma',
  6194. /**
  6195. * @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).
  6196. */
  6197. defaultValue: (Ext.isOpera || Ext.isIE6) ? '&#160;' : '&#8203;',
  6198. // private properties
  6199. actionMode: 'wrap',
  6200. validationEvent : false,
  6201. deferHeight: true,
  6202. initialized : false,
  6203. activated : false,
  6204. sourceEditMode : false,
  6205. onFocus : Ext.emptyFn,
  6206. iframePad:3,
  6207. hideMode:'offsets',
  6208. defaultAutoCreate : {
  6209. tag: "textarea",
  6210. style:"width:500px;height:300px;",
  6211. autocomplete: "off"
  6212. },
  6213. // private
  6214. initComponent : function(){
  6215. this.addEvents(
  6216. /**
  6217. * @event initialize
  6218. * Fires when the editor is fully initialized (including the iframe)
  6219. * @param {HtmlEditor} this
  6220. */
  6221. 'initialize',
  6222. /**
  6223. * @event activate
  6224. * Fires when the editor is first receives the focus. Any insertion must wait
  6225. * until after this event.
  6226. * @param {HtmlEditor} this
  6227. */
  6228. 'activate',
  6229. /**
  6230. * @event beforesync
  6231. * Fires before the textarea is updated with content from the editor iframe. Return false
  6232. * to cancel the sync.
  6233. * @param {HtmlEditor} this
  6234. * @param {String} html
  6235. */
  6236. 'beforesync',
  6237. /**
  6238. * @event beforepush
  6239. * Fires before the iframe editor is updated with content from the textarea. Return false
  6240. * to cancel the push.
  6241. * @param {HtmlEditor} this
  6242. * @param {String} html
  6243. */
  6244. 'beforepush',
  6245. /**
  6246. * @event sync
  6247. * Fires when the textarea is updated with content from the editor iframe.
  6248. * @param {HtmlEditor} this
  6249. * @param {String} html
  6250. */
  6251. 'sync',
  6252. /**
  6253. * @event push
  6254. * Fires when the iframe editor is updated with content from the textarea.
  6255. * @param {HtmlEditor} this
  6256. * @param {String} html
  6257. */
  6258. 'push',
  6259. /**
  6260. * @event editmodechange
  6261. * Fires when the editor switches edit modes
  6262. * @param {HtmlEditor} this
  6263. * @param {Boolean} sourceEdit True if source edit, false if standard editing.
  6264. */
  6265. 'editmodechange'
  6266. );
  6267. Ext.form.HtmlEditor.superclass.initComponent.call(this);
  6268. },
  6269. // private
  6270. createFontOptions : function(){
  6271. var buf = [], fs = this.fontFamilies, ff, lc;
  6272. for(var i = 0, len = fs.length; i< len; i++){
  6273. ff = fs[i];
  6274. lc = ff.toLowerCase();
  6275. buf.push(
  6276. '<option value="',lc,'" style="font-family:',ff,';"',
  6277. (this.defaultFont == lc ? ' selected="true">' : '>'),
  6278. ff,
  6279. '</option>'
  6280. );
  6281. }
  6282. return buf.join('');
  6283. },
  6284. /*
  6285. * Protected method that will not generally be called directly. It
  6286. * is called when the editor creates its toolbar. Override this method if you need to
  6287. * add custom toolbar buttons.
  6288. * @param {HtmlEditor} editor
  6289. */
  6290. createToolbar : function(editor){
  6291. var items = [];
  6292. var tipsEnabled = Ext.QuickTips && Ext.QuickTips.isEnabled();
  6293. function btn(id, toggle, handler){
  6294. return {
  6295. itemId : id,
  6296. cls : 'x-btn-icon',
  6297. iconCls: 'x-edit-'+id,
  6298. enableToggle:toggle !== false,
  6299. scope: editor,
  6300. handler:handler||editor.relayBtnCmd,
  6301. clickEvent:'mousedown',
  6302. tooltip: tipsEnabled ? editor.buttonTips[id] || undefined : undefined,
  6303. overflowText: editor.buttonTips[id].title || undefined,
  6304. tabIndex:-1
  6305. };
  6306. }
  6307. if(this.enableFont && !Ext.isSafari2){
  6308. var fontSelectItem = new Ext.Toolbar.Item({
  6309. autoEl: {
  6310. tag:'select',
  6311. cls:'x-font-select',
  6312. html: this.createFontOptions()
  6313. }
  6314. });
  6315. items.push(
  6316. fontSelectItem,
  6317. '-'
  6318. );
  6319. }
  6320. if(this.enableFormat){
  6321. items.push(
  6322. btn('bold'),
  6323. btn('italic'),
  6324. btn('underline')
  6325. );
  6326. }
  6327. if(this.enableFontSize){
  6328. items.push(
  6329. '-',
  6330. btn('increasefontsize', false, this.adjustFont),
  6331. btn('decreasefontsize', false, this.adjustFont)
  6332. );
  6333. }
  6334. if(this.enableColors){
  6335. items.push(
  6336. '-', {
  6337. itemId:'forecolor',
  6338. cls:'x-btn-icon',
  6339. iconCls: 'x-edit-forecolor',
  6340. clickEvent:'mousedown',
  6341. tooltip: tipsEnabled ? editor.buttonTips.forecolor || undefined : undefined,
  6342. tabIndex:-1,
  6343. menu : new Ext.menu.ColorMenu({
  6344. allowReselect: true,
  6345. focus: Ext.emptyFn,
  6346. value:'000000',
  6347. plain:true,
  6348. listeners: {
  6349. scope: this,
  6350. select: function(cp, color){
  6351. this.execCmd('forecolor', Ext.isWebKit || Ext.isIE ? '#'+color : color);
  6352. this.deferFocus();
  6353. }
  6354. },
  6355. clickEvent:'mousedown'
  6356. })
  6357. }, {
  6358. itemId:'backcolor',
  6359. cls:'x-btn-icon',
  6360. iconCls: 'x-edit-backcolor',
  6361. clickEvent:'mousedown',
  6362. tooltip: tipsEnabled ? editor.buttonTips.backcolor || undefined : undefined,
  6363. tabIndex:-1,
  6364. menu : new Ext.menu.ColorMenu({
  6365. focus: Ext.emptyFn,
  6366. value:'FFFFFF',
  6367. plain:true,
  6368. allowReselect: true,
  6369. listeners: {
  6370. scope: this,
  6371. select: function(cp, color){
  6372. if(Ext.isGecko){
  6373. this.execCmd('useCSS', false);
  6374. this.execCmd('hilitecolor', color);
  6375. this.execCmd('useCSS', true);
  6376. this.deferFocus();
  6377. }else{
  6378. this.execCmd(Ext.isOpera ? 'hilitecolor' : 'backcolor', Ext.isWebKit || Ext.isIE ? '#'+color : color);
  6379. this.deferFocus();
  6380. }
  6381. }
  6382. },
  6383. clickEvent:'mousedown'
  6384. })
  6385. }
  6386. );
  6387. }
  6388. if(this.enableAlignments){
  6389. items.push(
  6390. '-',
  6391. btn('justifyleft'),
  6392. btn('justifycenter'),
  6393. btn('justifyright')
  6394. );
  6395. }
  6396. if(!Ext.isSafari2){
  6397. if(this.enableLinks){
  6398. items.push(
  6399. '-',
  6400. btn('createlink', false, this.createLink)
  6401. );
  6402. }
  6403. if(this.enableLists){
  6404. items.push(
  6405. '-',
  6406. btn('insertorderedlist'),
  6407. btn('insertunorderedlist')
  6408. );
  6409. }
  6410. if(this.enableSourceEdit){
  6411. items.push(
  6412. '-',
  6413. btn('sourceedit', true, function(btn){
  6414. this.toggleSourceEdit(!this.sourceEditMode);
  6415. })
  6416. );
  6417. }
  6418. }
  6419. // build the toolbar
  6420. var tb = new Ext.Toolbar({
  6421. renderTo: this.wrap.dom.firstChild,
  6422. items: items
  6423. });
  6424. if (fontSelectItem) {
  6425. this.fontSelect = fontSelectItem.el;
  6426. this.mon(this.fontSelect, 'change', function(){
  6427. var font = this.fontSelect.dom.value;
  6428. this.relayCmd('fontname', font);
  6429. this.deferFocus();
  6430. }, this);
  6431. }
  6432. // stop form submits
  6433. this.mon(tb.el, 'click', function(e){
  6434. e.preventDefault();
  6435. });
  6436. this.tb = tb;
  6437. this.tb.doLayout();
  6438. },
  6439. onDisable: function(){
  6440. this.wrap.mask();
  6441. Ext.form.HtmlEditor.superclass.onDisable.call(this);
  6442. },
  6443. onEnable: function(){
  6444. this.wrap.unmask();
  6445. Ext.form.HtmlEditor.superclass.onEnable.call(this);
  6446. },
  6447. setReadOnly: function(readOnly){
  6448. Ext.form.HtmlEditor.superclass.setReadOnly.call(this, readOnly);
  6449. if(this.initialized){
  6450. if(Ext.isIE){
  6451. this.getEditorBody().contentEditable = !readOnly;
  6452. }else{
  6453. this.setDesignMode(!readOnly);
  6454. }
  6455. var bd = this.getEditorBody();
  6456. if(bd){
  6457. bd.style.cursor = this.readOnly ? 'default' : 'text';
  6458. }
  6459. this.disableItems(readOnly);
  6460. }
  6461. },
  6462. /**
  6463. * Protected method that will not generally be called directly. It
  6464. * is called when the editor initializes the iframe with HTML contents. Override this method if you
  6465. * want to change the initialization markup of the iframe (e.g. to add stylesheets).
  6466. *
  6467. * Note: IE8-Standards has unwanted scroller behavior, so the default meta tag forces IE7 compatibility
  6468. */
  6469. getDocMarkup : function(){
  6470. var h = Ext.fly(this.iframe).getHeight() - this.iframePad * 2;
  6471. 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);
  6472. },
  6473. // private
  6474. getEditorBody : function(){
  6475. var doc = this.getDoc();
  6476. return doc.body || doc.documentElement;
  6477. },
  6478. // private
  6479. getDoc : function(){
  6480. return Ext.isIE ? this.getWin().document : (this.iframe.contentDocument || this.getWin().document);
  6481. },
  6482. // private
  6483. getWin : function(){
  6484. return Ext.isIE ? this.iframe.contentWindow : window.frames[this.iframe.name];
  6485. },
  6486. // private
  6487. onRender : function(ct, position){
  6488. Ext.form.HtmlEditor.superclass.onRender.call(this, ct, position);
  6489. this.el.dom.style.border = '0 none';
  6490. this.el.dom.setAttribute('tabIndex', -1);
  6491. this.el.addClass('x-hidden');
  6492. if(Ext.isIE){ // fix IE 1px bogus margin
  6493. this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;');
  6494. }
  6495. this.wrap = this.el.wrap({
  6496. cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
  6497. });
  6498. this.createToolbar(this);
  6499. this.disableItems(true);
  6500. this.tb.doLayout();
  6501. this.createIFrame();
  6502. if(!this.width){
  6503. var sz = this.el.getSize();
  6504. this.setSize(sz.width, this.height || sz.height);
  6505. }
  6506. this.resizeEl = this.positionEl = this.wrap;
  6507. },
  6508. createIFrame: function(){
  6509. var iframe = document.createElement('iframe');
  6510. iframe.name = Ext.id();
  6511. iframe.frameBorder = '0';
  6512. iframe.style.overflow = 'auto';
  6513. iframe.src = Ext.SSL_SECURE_URL;
  6514. this.wrap.dom.appendChild(iframe);
  6515. this.iframe = iframe;
  6516. this.monitorTask = Ext.TaskMgr.start({
  6517. run: this.checkDesignMode,
  6518. scope: this,
  6519. interval:100
  6520. });
  6521. },
  6522. initFrame : function(){
  6523. Ext.TaskMgr.stop(this.monitorTask);
  6524. var doc = this.getDoc();
  6525. this.win = this.getWin();
  6526. doc.open();
  6527. doc.write(this.getDocMarkup());
  6528. doc.close();
  6529. var task = { // must defer to wait for browser to be ready
  6530. run : function(){
  6531. var doc = this.getDoc();
  6532. if(doc.body || doc.readyState == 'complete'){
  6533. Ext.TaskMgr.stop(task);
  6534. this.setDesignMode(true);
  6535. this.initEditor.defer(10, this);
  6536. }
  6537. },
  6538. interval : 10,
  6539. duration:10000,
  6540. scope: this
  6541. };
  6542. Ext.TaskMgr.start(task);
  6543. },
  6544. checkDesignMode : function(){
  6545. if(this.wrap && this.wrap.dom.offsetWidth){
  6546. var doc = this.getDoc();
  6547. if(!doc){
  6548. return;
  6549. }
  6550. if(!doc.editorInitialized || this.getDesignMode() != 'on'){
  6551. this.initFrame();
  6552. }
  6553. }
  6554. },
  6555. /* private
  6556. * set current design mode. To enable, mode can be true or 'on', off otherwise
  6557. */
  6558. setDesignMode : function(mode){
  6559. var doc = this.getDoc();
  6560. if (doc) {
  6561. if(this.readOnly){
  6562. mode = false;
  6563. }
  6564. doc.designMode = (/on|true/i).test(String(mode).toLowerCase()) ?'on':'off';
  6565. }
  6566. },
  6567. // private
  6568. getDesignMode : function(){
  6569. var doc = this.getDoc();
  6570. if(!doc){ return ''; }
  6571. return String(doc.designMode).toLowerCase();
  6572. },
  6573. disableItems: function(disabled){
  6574. if(this.fontSelect){
  6575. this.fontSelect.dom.disabled = disabled;
  6576. }
  6577. this.tb.items.each(function(item){
  6578. if(item.getItemId() != 'sourceedit'){
  6579. item.setDisabled(disabled);
  6580. }
  6581. });
  6582. },
  6583. // private
  6584. onResize : function(w, h){
  6585. Ext.form.HtmlEditor.superclass.onResize.apply(this, arguments);
  6586. if(this.el && this.iframe){
  6587. if(Ext.isNumber(w)){
  6588. var aw = w - this.wrap.getFrameWidth('lr');
  6589. this.el.setWidth(aw);
  6590. this.tb.setWidth(aw);
  6591. this.iframe.style.width = Math.max(aw, 0) + 'px';
  6592. }
  6593. if(Ext.isNumber(h)){
  6594. var ah = h - this.wrap.getFrameWidth('tb') - this.tb.el.getHeight();
  6595. this.el.setHeight(ah);
  6596. this.iframe.style.height = Math.max(ah, 0) + 'px';
  6597. var bd = this.getEditorBody();
  6598. if(bd){
  6599. bd.style.height = Math.max((ah - (this.iframePad*2)), 0) + 'px';
  6600. }
  6601. }
  6602. }
  6603. },
  6604. /**
  6605. * Toggles the editor between standard and source edit mode.
  6606. * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
  6607. */
  6608. toggleSourceEdit : function(sourceEditMode){
  6609. var iframeHeight,
  6610. elHeight;
  6611. if (sourceEditMode === undefined) {
  6612. sourceEditMode = !this.sourceEditMode;
  6613. }
  6614. this.sourceEditMode = sourceEditMode === true;
  6615. var btn = this.tb.getComponent('sourceedit');
  6616. if (btn.pressed !== this.sourceEditMode) {
  6617. btn.toggle(this.sourceEditMode);
  6618. if (!btn.xtbHidden) {
  6619. return;
  6620. }
  6621. }
  6622. if (this.sourceEditMode) {
  6623. // grab the height of the containing panel before we hide the iframe
  6624. this.previousSize = this.getSize();
  6625. iframeHeight = Ext.get(this.iframe).getHeight();
  6626. this.disableItems(true);
  6627. this.syncValue();
  6628. this.iframe.className = 'x-hidden';
  6629. this.el.removeClass('x-hidden');
  6630. this.el.dom.removeAttribute('tabIndex');
  6631. this.el.focus();
  6632. this.el.dom.style.height = iframeHeight + 'px';
  6633. }
  6634. else {
  6635. elHeight = parseInt(this.el.dom.style.height, 10);
  6636. if (this.initialized) {
  6637. this.disableItems(this.readOnly);
  6638. }
  6639. this.pushValue();
  6640. this.iframe.className = '';
  6641. this.el.addClass('x-hidden');
  6642. this.el.dom.setAttribute('tabIndex', -1);
  6643. this.deferFocus();
  6644. this.setSize(this.previousSize);
  6645. delete this.previousSize;
  6646. this.iframe.style.height = elHeight + 'px';
  6647. }
  6648. this.fireEvent('editmodechange', this, this.sourceEditMode);
  6649. },
  6650. // private used internally
  6651. createLink : function() {
  6652. var url = prompt(this.createLinkText, this.defaultLinkValue);
  6653. if(url && url != 'http:/'+'/'){
  6654. this.relayCmd('createlink', url);
  6655. }
  6656. },
  6657. // private
  6658. initEvents : function(){
  6659. this.originalValue = this.getValue();
  6660. },
  6661. /**
  6662. * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
  6663. * @method
  6664. */
  6665. markInvalid : Ext.emptyFn,
  6666. /**
  6667. * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
  6668. * @method
  6669. */
  6670. clearInvalid : Ext.emptyFn,
  6671. // docs inherit from Field
  6672. setValue : function(v){
  6673. Ext.form.HtmlEditor.superclass.setValue.call(this, v);
  6674. this.pushValue();
  6675. return this;
  6676. },
  6677. /**
  6678. * Protected method that will not generally be called directly. If you need/want
  6679. * custom HTML cleanup, this is the method you should override.
  6680. * @param {String} html The HTML to be cleaned
  6681. * @return {String} The cleaned HTML
  6682. */
  6683. cleanHtml: function(html) {
  6684. html = String(html);
  6685. if(Ext.isWebKit){ // strip safari nonsense
  6686. html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
  6687. }
  6688. /*
  6689. * Neat little hack. Strips out all the non-digit characters from the default
  6690. * value and compares it to the character code of the first character in the string
  6691. * because it can cause encoding issues when posted to the server.
  6692. */
  6693. if(html.charCodeAt(0) == this.defaultValue.replace(/\D/g, '')){
  6694. html = html.substring(1);
  6695. }
  6696. return html;
  6697. },
  6698. /**
  6699. * Protected method that will not generally be called directly. Syncs the contents
  6700. * of the editor iframe with the textarea.
  6701. */
  6702. syncValue : function(){
  6703. if(this.initialized){
  6704. var bd = this.getEditorBody();
  6705. var html = bd.innerHTML;
  6706. if(Ext.isWebKit){
  6707. var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
  6708. var m = bs.match(/text-align:(.*?);/i);
  6709. if(m && m[1]){
  6710. html = '<div style="'+m[0]+'">' + html + '</div>';
  6711. }
  6712. }
  6713. html = this.cleanHtml(html);
  6714. if(this.fireEvent('beforesync', this, html) !== false){
  6715. this.el.dom.value = html;
  6716. this.fireEvent('sync', this, html);
  6717. }
  6718. }
  6719. },
  6720. //docs inherit from Field
  6721. getValue : function() {
  6722. this[this.sourceEditMode ? 'pushValue' : 'syncValue']();
  6723. return Ext.form.HtmlEditor.superclass.getValue.call(this);
  6724. },
  6725. /**
  6726. * Protected method that will not generally be called directly. Pushes the value of the textarea
  6727. * into the iframe editor.
  6728. */
  6729. pushValue : function(){
  6730. if(this.initialized){
  6731. var v = this.el.dom.value;
  6732. if(!this.activated && v.length < 1){
  6733. v = this.defaultValue;
  6734. }
  6735. if(this.fireEvent('beforepush', this, v) !== false){
  6736. this.getEditorBody().innerHTML = v;
  6737. if(Ext.isGecko){
  6738. // Gecko hack, see: https://bugzilla.mozilla.org/show_bug.cgi?id=232791#c8
  6739. this.setDesignMode(false); //toggle off first
  6740. this.setDesignMode(true);
  6741. }
  6742. this.fireEvent('push', this, v);
  6743. }
  6744. }
  6745. },
  6746. // private
  6747. deferFocus : function(){
  6748. this.focus.defer(10, this);
  6749. },
  6750. // docs inherit from Field
  6751. focus : function(){
  6752. if(this.win && !this.sourceEditMode){
  6753. this.win.focus();
  6754. }else{
  6755. this.el.focus();
  6756. }
  6757. },
  6758. // private
  6759. initEditor : function(){
  6760. //Destroying the component during/before initEditor can cause issues.
  6761. try{
  6762. var dbody = this.getEditorBody(),
  6763. ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat', 'background-color', 'color'),
  6764. doc,
  6765. fn;
  6766. ss['background-attachment'] = 'fixed'; // w3c
  6767. dbody.bgProperties = 'fixed'; // ie
  6768. Ext.DomHelper.applyStyles(dbody, ss);
  6769. doc = this.getDoc();
  6770. if(doc){
  6771. try{
  6772. Ext.EventManager.removeAll(doc);
  6773. }catch(e){}
  6774. }
  6775. /*
  6776. * We need to use createDelegate here, because when using buffer, the delayed task is added
  6777. * as a property to the function. When the listener is removed, the task is deleted from the function.
  6778. * Since onEditorEvent is shared on the prototype, if we have multiple html editors, the first time one of the editors
  6779. * is destroyed, it causes the fn to be deleted from the prototype, which causes errors. Essentially, we're just anonymizing the function.
  6780. */
  6781. fn = this.onEditorEvent.createDelegate(this);
  6782. Ext.EventManager.on(doc, {
  6783. mousedown: fn,
  6784. dblclick: fn,
  6785. click: fn,
  6786. keyup: fn,
  6787. buffer:100
  6788. });
  6789. if(Ext.isGecko){
  6790. Ext.EventManager.on(doc, 'keypress', this.applyCommand, this);
  6791. }
  6792. if(Ext.isIE || Ext.isWebKit || Ext.isOpera){
  6793. Ext.EventManager.on(doc, 'keydown', this.fixKeys, this);
  6794. }
  6795. doc.editorInitialized = true;
  6796. this.initialized = true;
  6797. this.pushValue();
  6798. this.setReadOnly(this.readOnly);
  6799. this.fireEvent('initialize', this);
  6800. }catch(e){}
  6801. },
  6802. // private
  6803. beforeDestroy : function(){
  6804. if(this.monitorTask){
  6805. Ext.TaskMgr.stop(this.monitorTask);
  6806. }
  6807. if(this.rendered){
  6808. Ext.destroy(this.tb);
  6809. var doc = this.getDoc();
  6810. if(doc){
  6811. try{
  6812. Ext.EventManager.removeAll(doc);
  6813. for (var prop in doc){
  6814. delete doc[prop];
  6815. }
  6816. }catch(e){}
  6817. }
  6818. if(this.wrap){
  6819. this.wrap.dom.innerHTML = '';
  6820. this.wrap.remove();
  6821. }
  6822. }
  6823. Ext.form.HtmlEditor.superclass.beforeDestroy.call(this);
  6824. },
  6825. // private
  6826. onFirstFocus : function(){
  6827. this.activated = true;
  6828. this.disableItems(this.readOnly);
  6829. if(Ext.isGecko){ // prevent silly gecko errors
  6830. this.win.focus();
  6831. var s = this.win.getSelection();
  6832. if(!s.focusNode || s.focusNode.nodeType != 3){
  6833. var r = s.getRangeAt(0);
  6834. r.selectNodeContents(this.getEditorBody());
  6835. r.collapse(true);
  6836. this.deferFocus();
  6837. }
  6838. try{
  6839. this.execCmd('useCSS', true);
  6840. this.execCmd('styleWithCSS', false);
  6841. }catch(e){}
  6842. }
  6843. this.fireEvent('activate', this);
  6844. },
  6845. // private
  6846. adjustFont: function(btn){
  6847. var adjust = btn.getItemId() == 'increasefontsize' ? 1 : -1,
  6848. doc = this.getDoc(),
  6849. v = parseInt(doc.queryCommandValue('FontSize') || 2, 10);
  6850. if((Ext.isSafari && !Ext.isSafari2) || Ext.isChrome || Ext.isAir){
  6851. // Safari 3 values
  6852. // 1 = 10px, 2 = 13px, 3 = 16px, 4 = 18px, 5 = 24px, 6 = 32px
  6853. if(v <= 10){
  6854. v = 1 + adjust;
  6855. }else if(v <= 13){
  6856. v = 2 + adjust;
  6857. }else if(v <= 16){
  6858. v = 3 + adjust;
  6859. }else if(v <= 18){
  6860. v = 4 + adjust;
  6861. }else if(v <= 24){
  6862. v = 5 + adjust;
  6863. }else {
  6864. v = 6 + adjust;
  6865. }
  6866. v = v.constrain(1, 6);
  6867. }else{
  6868. if(Ext.isSafari){ // safari
  6869. adjust *= 2;
  6870. }
  6871. v = Math.max(1, v+adjust) + (Ext.isSafari ? 'px' : 0);
  6872. }
  6873. this.execCmd('FontSize', v);
  6874. },
  6875. // private
  6876. onEditorEvent : function(e){
  6877. this.updateToolbar();
  6878. },
  6879. /**
  6880. * Protected method that will not generally be called directly. It triggers
  6881. * a toolbar update by reading the markup state of the current selection in the editor.
  6882. */
  6883. updateToolbar: function(){
  6884. if(this.readOnly){
  6885. return;
  6886. }
  6887. if(!this.activated){
  6888. this.onFirstFocus();
  6889. return;
  6890. }
  6891. var btns = this.tb.items.map,
  6892. doc = this.getDoc();
  6893. if(this.enableFont && !Ext.isSafari2){
  6894. var name = (doc.queryCommandValue('FontName')||this.defaultFont).toLowerCase();
  6895. if(name != this.fontSelect.dom.value){
  6896. this.fontSelect.dom.value = name;
  6897. }
  6898. }
  6899. if(this.enableFormat){
  6900. btns.bold.toggle(doc.queryCommandState('bold'));
  6901. btns.italic.toggle(doc.queryCommandState('italic'));
  6902. btns.underline.toggle(doc.queryCommandState('underline'));
  6903. }
  6904. if(this.enableAlignments){
  6905. btns.justifyleft.toggle(doc.queryCommandState('justifyleft'));
  6906. btns.justifycenter.toggle(doc.queryCommandState('justifycenter'));
  6907. btns.justifyright.toggle(doc.queryCommandState('justifyright'));
  6908. }
  6909. if(!Ext.isSafari2 && this.enableLists){
  6910. btns.insertorderedlist.toggle(doc.queryCommandState('insertorderedlist'));
  6911. btns.insertunorderedlist.toggle(doc.queryCommandState('insertunorderedlist'));
  6912. }
  6913. Ext.menu.MenuMgr.hideAll();
  6914. this.syncValue();
  6915. },
  6916. // private
  6917. relayBtnCmd : function(btn){
  6918. this.relayCmd(btn.getItemId());
  6919. },
  6920. /**
  6921. * Executes a Midas editor command on the editor document and performs necessary focus and
  6922. * toolbar updates. <b>This should only be called after the editor is initialized.</b>
  6923. * @param {String} cmd The Midas command
  6924. * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
  6925. */
  6926. relayCmd : function(cmd, value){
  6927. (function(){
  6928. this.focus();
  6929. this.execCmd(cmd, value);
  6930. this.updateToolbar();
  6931. }).defer(10, this);
  6932. },
  6933. /**
  6934. * Executes a Midas editor command directly on the editor document.
  6935. * For visual commands, you should use {@link #relayCmd} instead.
  6936. * <b>This should only be called after the editor is initialized.</b>
  6937. * @param {String} cmd The Midas command
  6938. * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
  6939. */
  6940. execCmd : function(cmd, value){
  6941. var doc = this.getDoc();
  6942. doc.execCommand(cmd, false, value === undefined ? null : value);
  6943. this.syncValue();
  6944. },
  6945. // private
  6946. applyCommand : function(e){
  6947. if(e.ctrlKey){
  6948. var c = e.getCharCode(), cmd;
  6949. if(c > 0){
  6950. c = String.fromCharCode(c);
  6951. switch(c){
  6952. case 'b':
  6953. cmd = 'bold';
  6954. break;
  6955. case 'i':
  6956. cmd = 'italic';
  6957. break;
  6958. case 'u':
  6959. cmd = 'underline';
  6960. break;
  6961. }
  6962. if(cmd){
  6963. this.win.focus();
  6964. this.execCmd(cmd);
  6965. this.deferFocus();
  6966. e.preventDefault();
  6967. }
  6968. }
  6969. }
  6970. },
  6971. /**
  6972. * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
  6973. * to insert text.
  6974. * @param {String} text
  6975. */
  6976. insertAtCursor : function(text){
  6977. if(!this.activated){
  6978. return;
  6979. }
  6980. if(Ext.isIE){
  6981. this.win.focus();
  6982. var doc = this.getDoc(),
  6983. r = doc.selection.createRange();
  6984. if(r){
  6985. r.pasteHTML(text);
  6986. this.syncValue();
  6987. this.deferFocus();
  6988. }
  6989. }else{
  6990. this.win.focus();
  6991. this.execCmd('InsertHTML', text);
  6992. this.deferFocus();
  6993. }
  6994. },
  6995. // private
  6996. fixKeys : function(){ // load time branching for fastest keydown performance
  6997. if(Ext.isIE){
  6998. return function(e){
  6999. var k = e.getKey(),
  7000. doc = this.getDoc(),
  7001. r;
  7002. if(k == e.TAB){
  7003. e.stopEvent();
  7004. r = doc.selection.createRange();
  7005. if(r){
  7006. r.collapse(true);
  7007. r.pasteHTML('&nbsp;&nbsp;&nbsp;&nbsp;');
  7008. this.deferFocus();
  7009. }
  7010. }else if(k == e.ENTER){
  7011. r = doc.selection.createRange();
  7012. if(r){
  7013. var target = r.parentElement();
  7014. if(!target || target.tagName.toLowerCase() != 'li'){
  7015. e.stopEvent();
  7016. r.pasteHTML('<br />');
  7017. r.collapse(false);
  7018. r.select();
  7019. }
  7020. }
  7021. }
  7022. };
  7023. }else if(Ext.isOpera){
  7024. return function(e){
  7025. var k = e.getKey();
  7026. if(k == e.TAB){
  7027. e.stopEvent();
  7028. this.win.focus();
  7029. this.execCmd('InsertHTML','&nbsp;&nbsp;&nbsp;&nbsp;');
  7030. this.deferFocus();
  7031. }
  7032. };
  7033. }else if(Ext.isWebKit){
  7034. return function(e){
  7035. var k = e.getKey();
  7036. if(k == e.TAB){
  7037. e.stopEvent();
  7038. this.execCmd('InsertText','\t');
  7039. this.deferFocus();
  7040. }else if(k == e.ENTER){
  7041. e.stopEvent();
  7042. this.execCmd('InsertHtml','<br /><br />');
  7043. this.deferFocus();
  7044. }
  7045. };
  7046. }
  7047. }(),
  7048. /**
  7049. * Returns the editor's toolbar. <b>This is only available after the editor has been rendered.</b>
  7050. * @return {Ext.Toolbar}
  7051. */
  7052. getToolbar : function(){
  7053. return this.tb;
  7054. },
  7055. /**
  7056. * Object collection of toolbar tooltips for the buttons in the editor. The key
  7057. * is the command id associated with that button and the value is a valid QuickTips object.
  7058. * For example:
  7059. <pre><code>
  7060. {
  7061. bold : {
  7062. title: 'Bold (Ctrl+B)',
  7063. text: 'Make the selected text bold.',
  7064. cls: 'x-html-editor-tip'
  7065. },
  7066. italic : {
  7067. title: 'Italic (Ctrl+I)',
  7068. text: 'Make the selected text italic.',
  7069. cls: 'x-html-editor-tip'
  7070. },
  7071. ...
  7072. </code></pre>
  7073. * @type Object
  7074. */
  7075. buttonTips : {
  7076. bold : {
  7077. title: 'Bold (Ctrl+B)',
  7078. text: 'Make the selected text bold.',
  7079. cls: 'x-html-editor-tip'
  7080. },
  7081. italic : {
  7082. title: 'Italic (Ctrl+I)',
  7083. text: 'Make the selected text italic.',
  7084. cls: 'x-html-editor-tip'
  7085. },
  7086. underline : {
  7087. title: 'Underline (Ctrl+U)',
  7088. text: 'Underline the selected text.',
  7089. cls: 'x-html-editor-tip'
  7090. },
  7091. increasefontsize : {
  7092. title: 'Grow Text',
  7093. text: 'Increase the font size.',
  7094. cls: 'x-html-editor-tip'
  7095. },
  7096. decreasefontsize : {
  7097. title: 'Shrink Text',
  7098. text: 'Decrease the font size.',
  7099. cls: 'x-html-editor-tip'
  7100. },
  7101. backcolor : {
  7102. title: 'Text Highlight Color',
  7103. text: 'Change the background color of the selected text.',
  7104. cls: 'x-html-editor-tip'
  7105. },
  7106. forecolor : {
  7107. title: 'Font Color',
  7108. text: 'Change the color of the selected text.',
  7109. cls: 'x-html-editor-tip'
  7110. },
  7111. justifyleft : {
  7112. title: 'Align Text Left',
  7113. text: 'Align text to the left.',
  7114. cls: 'x-html-editor-tip'
  7115. },
  7116. justifycenter : {
  7117. title: 'Center Text',
  7118. text: 'Center text in the editor.',
  7119. cls: 'x-html-editor-tip'
  7120. },
  7121. justifyright : {
  7122. title: 'Align Text Right',
  7123. text: 'Align text to the right.',
  7124. cls: 'x-html-editor-tip'
  7125. },
  7126. insertunorderedlist : {
  7127. title: 'Bullet List',
  7128. text: 'Start a bulleted list.',
  7129. cls: 'x-html-editor-tip'
  7130. },
  7131. insertorderedlist : {
  7132. title: 'Numbered List',
  7133. text: 'Start a numbered list.',
  7134. cls: 'x-html-editor-tip'
  7135. },
  7136. createlink : {
  7137. title: 'Hyperlink',
  7138. text: 'Make the selected text a hyperlink.',
  7139. cls: 'x-html-editor-tip'
  7140. },
  7141. sourceedit : {
  7142. title: 'Source Edit',
  7143. text: 'Switch to source editing mode.',
  7144. cls: 'x-html-editor-tip'
  7145. }
  7146. }
  7147. // hide stuff that is not compatible
  7148. /**
  7149. * @event blur
  7150. * @hide
  7151. */
  7152. /**
  7153. * @event change
  7154. * @hide
  7155. */
  7156. /**
  7157. * @event focus
  7158. * @hide
  7159. */
  7160. /**
  7161. * @event specialkey
  7162. * @hide
  7163. */
  7164. /**
  7165. * @cfg {String} fieldClass @hide
  7166. */
  7167. /**
  7168. * @cfg {String} focusClass @hide
  7169. */
  7170. /**
  7171. * @cfg {String} autoCreate @hide
  7172. */
  7173. /**
  7174. * @cfg {String} inputType @hide
  7175. */
  7176. /**
  7177. * @cfg {String} invalidClass @hide
  7178. */
  7179. /**
  7180. * @cfg {String} invalidText @hide
  7181. */
  7182. /**
  7183. * @cfg {String} msgFx @hide
  7184. */
  7185. /**
  7186. * @cfg {String} validateOnBlur @hide
  7187. */
  7188. /**
  7189. * @cfg {Boolean} allowDomMove @hide
  7190. */
  7191. /**
  7192. * @cfg {String} applyTo @hide
  7193. */
  7194. /**
  7195. * @cfg {String} autoHeight @hide
  7196. */
  7197. /**
  7198. * @cfg {String} autoWidth @hide
  7199. */
  7200. /**
  7201. * @cfg {String} cls @hide
  7202. */
  7203. /**
  7204. * @cfg {String} disabled @hide
  7205. */
  7206. /**
  7207. * @cfg {String} disabledClass @hide
  7208. */
  7209. /**
  7210. * @cfg {String} msgTarget @hide
  7211. */
  7212. /**
  7213. * @cfg {String} readOnly @hide
  7214. */
  7215. /**
  7216. * @cfg {String} style @hide
  7217. */
  7218. /**
  7219. * @cfg {String} validationDelay @hide
  7220. */
  7221. /**
  7222. * @cfg {String} validationEvent @hide
  7223. */
  7224. /**
  7225. * @cfg {String} tabIndex @hide
  7226. */
  7227. /**
  7228. * @property disabled
  7229. * @hide
  7230. */
  7231. /**
  7232. * @method applyToMarkup
  7233. * @hide
  7234. */
  7235. /**
  7236. * @method disable
  7237. * @hide
  7238. */
  7239. /**
  7240. * @method enable
  7241. * @hide
  7242. */
  7243. /**
  7244. * @method validate
  7245. * @hide
  7246. */
  7247. /**
  7248. * @event valid
  7249. * @hide
  7250. */
  7251. /**
  7252. * @method setDisabled
  7253. * @hide
  7254. */
  7255. /**
  7256. * @cfg keys
  7257. * @hide
  7258. */
  7259. });
  7260. Ext.reg('htmleditor', Ext.form.HtmlEditor);
  7261. /**
  7262. * @class Ext.form.TimeField
  7263. * @extends Ext.form.ComboBox
  7264. * Provides a time input field with a time dropdown and automatic time validation. Example usage:
  7265. * <pre><code>
  7266. new Ext.form.TimeField({
  7267. minValue: '9:00 AM',
  7268. maxValue: '6:00 PM',
  7269. increment: 30
  7270. });
  7271. </code></pre>
  7272. * @constructor
  7273. * Create a new TimeField
  7274. * @param {Object} config
  7275. * @xtype timefield
  7276. */
  7277. Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
  7278. /**
  7279. * @cfg {Date/String} minValue
  7280. * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string
  7281. * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
  7282. */
  7283. minValue : undefined,
  7284. /**
  7285. * @cfg {Date/String} maxValue
  7286. * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string
  7287. * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
  7288. */
  7289. maxValue : undefined,
  7290. /**
  7291. * @cfg {String} minText
  7292. * The error text to display when the date in the cell is before minValue (defaults to
  7293. * 'The time in this field must be equal to or after {0}').
  7294. */
  7295. minText : "The time in this field must be equal to or after {0}",
  7296. /**
  7297. * @cfg {String} maxText
  7298. * The error text to display when the time is after maxValue (defaults to
  7299. * 'The time in this field must be equal to or before {0}').
  7300. */
  7301. maxText : "The time in this field must be equal to or before {0}",
  7302. /**
  7303. * @cfg {String} invalidText
  7304. * The error text to display when the time in the field is invalid (defaults to
  7305. * '{value} is not a valid time').
  7306. */
  7307. invalidText : "{0} is not a valid time",
  7308. /**
  7309. * @cfg {String} format
  7310. * The default time format string which can be overriden for localization support. The format must be
  7311. * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
  7312. * format try 'H:i' instead.
  7313. */
  7314. format : "g:i A",
  7315. /**
  7316. * @cfg {String} altFormats
  7317. * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
  7318. * 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').
  7319. */
  7320. 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",
  7321. /**
  7322. * @cfg {Number} increment
  7323. * The number of minutes between each time value in the list (defaults to 15).
  7324. */
  7325. increment: 15,
  7326. // private override
  7327. mode: 'local',
  7328. // private override
  7329. triggerAction: 'all',
  7330. // private override
  7331. typeAhead: false,
  7332. // private - This is the date to use when generating time values in the absence of either minValue
  7333. // or maxValue. Using the current date causes DST issues on DST boundary dates, so this is an
  7334. // arbitrary "safe" date that can be any date aside from DST boundary dates.
  7335. initDate: '1/1/2008',
  7336. initDateFormat: 'j/n/Y',
  7337. // private
  7338. initComponent : function(){
  7339. if(Ext.isDefined(this.minValue)){
  7340. this.setMinValue(this.minValue, true);
  7341. }
  7342. if(Ext.isDefined(this.maxValue)){
  7343. this.setMaxValue(this.maxValue, true);
  7344. }
  7345. if(!this.store){
  7346. this.generateStore(true);
  7347. }
  7348. Ext.form.TimeField.superclass.initComponent.call(this);
  7349. },
  7350. /**
  7351. * Replaces any existing {@link #minValue} with the new time and refreshes the store.
  7352. * @param {Date/String} value The minimum time that can be selected
  7353. */
  7354. setMinValue: function(value, /* private */ initial){
  7355. this.setLimit(value, true, initial);
  7356. return this;
  7357. },
  7358. /**
  7359. * Replaces any existing {@link #maxValue} with the new time and refreshes the store.
  7360. * @param {Date/String} value The maximum time that can be selected
  7361. */
  7362. setMaxValue: function(value, /* private */ initial){
  7363. this.setLimit(value, false, initial);
  7364. return this;
  7365. },
  7366. // private
  7367. generateStore: function(initial){
  7368. var min = this.minValue || new Date(this.initDate).clearTime(),
  7369. max = this.maxValue || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1),
  7370. times = [];
  7371. while(min <= max){
  7372. times.push(min.dateFormat(this.format));
  7373. min = min.add('mi', this.increment);
  7374. }
  7375. this.bindStore(times, initial);
  7376. },
  7377. // private
  7378. setLimit: function(value, isMin, initial){
  7379. var d;
  7380. if(Ext.isString(value)){
  7381. d = this.parseDate(value);
  7382. }else if(Ext.isDate(value)){
  7383. d = value;
  7384. }
  7385. if(d){
  7386. var val = new Date(this.initDate).clearTime();
  7387. val.setHours(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
  7388. this[isMin ? 'minValue' : 'maxValue'] = val;
  7389. if(!initial){
  7390. this.generateStore();
  7391. }
  7392. }
  7393. },
  7394. // inherited docs
  7395. getValue : function(){
  7396. var v = Ext.form.TimeField.superclass.getValue.call(this);
  7397. return this.formatDate(this.parseDate(v)) || '';
  7398. },
  7399. // inherited docs
  7400. setValue : function(value){
  7401. return Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));
  7402. },
  7403. // private overrides
  7404. validateValue : Ext.form.DateField.prototype.validateValue,
  7405. formatDate : Ext.form.DateField.prototype.formatDate,
  7406. parseDate: function(value) {
  7407. if (!value || Ext.isDate(value)) {
  7408. return value;
  7409. }
  7410. var id = this.initDate + ' ',
  7411. idf = this.initDateFormat + ' ',
  7412. v = Date.parseDate(id + value, idf + this.format), // *** handle DST. note: this.format is a TIME-only format
  7413. af = this.altFormats;
  7414. if (!v && af) {
  7415. if (!this.altFormatsArray) {
  7416. this.altFormatsArray = af.split("|");
  7417. }
  7418. for (var i = 0, afa = this.altFormatsArray, len = afa.length; i < len && !v; i++) {
  7419. v = Date.parseDate(id + value, idf + afa[i]);
  7420. }
  7421. }
  7422. return v;
  7423. }
  7424. });
  7425. Ext.reg('timefield', Ext.form.TimeField);/**
  7426. * @class Ext.form.SliderField
  7427. * @extends Ext.form.Field
  7428. * Wraps a {@link Ext.slider.MultiSlider Slider} so it can be used as a form field.
  7429. * @constructor
  7430. * Creates a new SliderField
  7431. * @param {Object} config Configuration options. Note that you can pass in any slider configuration options, as well as
  7432. * as any field configuration options.
  7433. * @xtype sliderfield
  7434. */
  7435. Ext.form.SliderField = Ext.extend(Ext.form.Field, {
  7436. /**
  7437. * @cfg {Boolean} useTips
  7438. * True to use an Ext.slider.Tip to display tips for the value. Defaults to <tt>true</tt>.
  7439. */
  7440. useTips : true,
  7441. /**
  7442. * @cfg {Function} tipText
  7443. * A function used to display custom text for the slider tip. Defaults to <tt>null</tt>, which will
  7444. * use the default on the plugin.
  7445. */
  7446. tipText : null,
  7447. // private override
  7448. actionMode: 'wrap',
  7449. /**
  7450. * Initialize the component.
  7451. * @private
  7452. */
  7453. initComponent : function() {
  7454. var cfg = Ext.copyTo({
  7455. id: this.id + '-slider'
  7456. }, this.initialConfig, ['vertical', 'minValue', 'maxValue', 'decimalPrecision', 'keyIncrement', 'increment', 'clickToChange', 'animate']);
  7457. // only can use it if it exists.
  7458. if (this.useTips) {
  7459. var plug = this.tipText ? {getText: this.tipText} : {};
  7460. cfg.plugins = [new Ext.slider.Tip(plug)];
  7461. }
  7462. this.slider = new Ext.Slider(cfg);
  7463. Ext.form.SliderField.superclass.initComponent.call(this);
  7464. },
  7465. /**
  7466. * Set up the hidden field
  7467. * @param {Object} ct The container to render to.
  7468. * @param {Object} position The position in the container to render to.
  7469. * @private
  7470. */
  7471. onRender : function(ct, position){
  7472. this.autoCreate = {
  7473. id: this.id,
  7474. name: this.name,
  7475. type: 'hidden',
  7476. tag: 'input'
  7477. };
  7478. Ext.form.SliderField.superclass.onRender.call(this, ct, position);
  7479. this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
  7480. this.resizeEl = this.positionEl = this.wrap;
  7481. this.slider.render(this.wrap);
  7482. },
  7483. /**
  7484. * Ensure that the slider size is set automatically when the field resizes.
  7485. * @param {Object} w The width
  7486. * @param {Object} h The height
  7487. * @param {Object} aw The adjusted width
  7488. * @param {Object} ah The adjusted height
  7489. * @private
  7490. */
  7491. onResize : function(w, h, aw, ah){
  7492. Ext.form.SliderField.superclass.onResize.call(this, w, h, aw, ah);
  7493. this.slider.setSize(w, h);
  7494. },
  7495. /**
  7496. * Initialize any events for this class.
  7497. * @private
  7498. */
  7499. initEvents : function(){
  7500. Ext.form.SliderField.superclass.initEvents.call(this);
  7501. this.slider.on('change', this.onChange, this);
  7502. },
  7503. /**
  7504. * Utility method to set the value of the field when the slider changes.
  7505. * @param {Object} slider The slider object.
  7506. * @param {Object} v The new value.
  7507. * @private
  7508. */
  7509. onChange : function(slider, v){
  7510. this.setValue(v, undefined, true);
  7511. },
  7512. /**
  7513. * Enable the slider when the field is enabled.
  7514. * @private
  7515. */
  7516. onEnable : function(){
  7517. Ext.form.SliderField.superclass.onEnable.call(this);
  7518. this.slider.enable();
  7519. },
  7520. /**
  7521. * Disable the slider when the field is disabled.
  7522. * @private
  7523. */
  7524. onDisable : function(){
  7525. Ext.form.SliderField.superclass.onDisable.call(this);
  7526. this.slider.disable();
  7527. },
  7528. /**
  7529. * Ensure the slider is destroyed when the field is destroyed.
  7530. * @private
  7531. */
  7532. beforeDestroy : function(){
  7533. Ext.destroy(this.slider);
  7534. Ext.form.SliderField.superclass.beforeDestroy.call(this);
  7535. },
  7536. /**
  7537. * If a side icon is shown, do alignment to the slider
  7538. * @private
  7539. */
  7540. alignErrorIcon : function(){
  7541. this.errorIcon.alignTo(this.slider.el, 'tl-tr', [2, 0]);
  7542. },
  7543. /**
  7544. * Sets the minimum field value.
  7545. * @param {Number} v The new minimum value.
  7546. * @return {Ext.form.SliderField} this
  7547. */
  7548. setMinValue : function(v){
  7549. this.slider.setMinValue(v);
  7550. return this;
  7551. },
  7552. /**
  7553. * Sets the maximum field value.
  7554. * @param {Number} v The new maximum value.
  7555. * @return {Ext.form.SliderField} this
  7556. */
  7557. setMaxValue : function(v){
  7558. this.slider.setMaxValue(v);
  7559. return this;
  7560. },
  7561. /**
  7562. * Sets the value for this field.
  7563. * @param {Number} v The new value.
  7564. * @param {Boolean} animate (optional) Whether to animate the transition. If not specified, it will default to the animate config.
  7565. * @return {Ext.form.SliderField} this
  7566. */
  7567. setValue : function(v, animate, /* private */ silent){
  7568. // silent is used if the setValue method is invoked by the slider
  7569. // which means we don't need to set the value on the slider.
  7570. if(!silent){
  7571. this.slider.setValue(v, animate);
  7572. }
  7573. return Ext.form.SliderField.superclass.setValue.call(this, this.slider.getValue());
  7574. },
  7575. /**
  7576. * Gets the current value for this field.
  7577. * @return {Number} The current value.
  7578. */
  7579. getValue : function(){
  7580. return this.slider.getValue();
  7581. }
  7582. });
  7583. Ext.reg('sliderfield', Ext.form.SliderField);/**
  7584. * @class Ext.form.Label
  7585. * @extends Ext.BoxComponent
  7586. * Basic Label field.
  7587. * @constructor
  7588. * Creates a new Label
  7589. * @param {Ext.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
  7590. * 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
  7591. * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
  7592. * @xtype label
  7593. */
  7594. Ext.form.Label = Ext.extend(Ext.BoxComponent, {
  7595. /**
  7596. * @cfg {String} text The plain text to display within the label (defaults to ''). If you need to include HTML
  7597. * tags within the label's innerHTML, use the {@link #html} config instead.
  7598. */
  7599. /**
  7600. * @cfg {String} forId The id of the input element to which this label will be bound via the standard HTML 'for'
  7601. * attribute. If not specified, the attribute will not be added to the label.
  7602. */
  7603. /**
  7604. * @cfg {String} html An HTML fragment that will be used as the label's innerHTML (defaults to '').
  7605. * Note that if {@link #text} is specified it will take precedence and this value will be ignored.
  7606. */
  7607. // private
  7608. onRender : function(ct, position){
  7609. if(!this.el){
  7610. this.el = document.createElement('label');
  7611. this.el.id = this.getId();
  7612. this.el.innerHTML = this.text ? Ext.util.Format.htmlEncode(this.text) : (this.html || '');
  7613. if(this.forId){
  7614. this.el.setAttribute('for', this.forId);
  7615. }
  7616. }
  7617. Ext.form.Label.superclass.onRender.call(this, ct, position);
  7618. },
  7619. /**
  7620. * Updates the label's innerHTML with the specified string.
  7621. * @param {String} text The new label text
  7622. * @param {Boolean} encode (optional) False to skip HTML-encoding the text when rendering it
  7623. * to the label (defaults to true which encodes the value). This might be useful if you want to include
  7624. * tags in the label's innerHTML rather than rendering them as string literals per the default logic.
  7625. * @return {Label} this
  7626. */
  7627. setText : function(t, encode){
  7628. var e = encode === false;
  7629. this[!e ? 'text' : 'html'] = t;
  7630. delete this[e ? 'text' : 'html'];
  7631. if(this.rendered){
  7632. this.el.dom.innerHTML = encode !== false ? Ext.util.Format.htmlEncode(t) : t;
  7633. }
  7634. return this;
  7635. }
  7636. });
  7637. Ext.reg('label', Ext.form.Label);/**
  7638. * @class Ext.form.Action
  7639. * <p>The subclasses of this class provide actions to perform upon {@link Ext.form.BasicForm Form}s.</p>
  7640. * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  7641. * the Form needs to perform an action such as submit or load. The Configuration options
  7642. * listed for this class are set through the Form's action methods: {@link Ext.form.BasicForm#submit submit},
  7643. * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}</p>
  7644. * <p>The instance of Action which performed the action is passed to the success
  7645. * and failure callbacks of the Form's action methods ({@link Ext.form.BasicForm#submit submit},
  7646. * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}),
  7647. * and to the {@link Ext.form.BasicForm#actioncomplete actioncomplete} and
  7648. * {@link Ext.form.BasicForm#actionfailed actionfailed} event handlers.</p>
  7649. */
  7650. Ext.form.Action = function(form, options){
  7651. this.form = form;
  7652. this.options = options || {};
  7653. };
  7654. /**
  7655. * Failure type returned when client side validation of the Form fails
  7656. * thus aborting a submit action. Client side validation is performed unless
  7657. * {@link #clientValidation} is explicitly set to <tt>false</tt>.
  7658. * @type {String}
  7659. * @static
  7660. */
  7661. Ext.form.Action.CLIENT_INVALID = 'client';
  7662. /**
  7663. * <p>Failure type returned when server side processing fails and the {@link #result}'s
  7664. * <tt style="font-weight:bold">success</tt> property is set to <tt>false</tt>.</p>
  7665. * <p>In the case of a form submission, field-specific error messages may be returned in the
  7666. * {@link #result}'s <tt style="font-weight:bold">errors</tt> property.</p>
  7667. * @type {String}
  7668. * @static
  7669. */
  7670. Ext.form.Action.SERVER_INVALID = 'server';
  7671. /**
  7672. * Failure type returned when a communication error happens when attempting
  7673. * to send a request to the remote server. The {@link #response} may be examined to
  7674. * provide further information.
  7675. * @type {String}
  7676. * @static
  7677. */
  7678. Ext.form.Action.CONNECT_FAILURE = 'connect';
  7679. /**
  7680. * Failure type returned when the response's <tt style="font-weight:bold">success</tt>
  7681. * property is set to <tt>false</tt>, or no field values are returned in the response's
  7682. * <tt style="font-weight:bold">data</tt> property.
  7683. * @type {String}
  7684. * @static
  7685. */
  7686. Ext.form.Action.LOAD_FAILURE = 'load';
  7687. Ext.form.Action.prototype = {
  7688. /**
  7689. * @cfg {String} url The URL that the Action is to invoke.
  7690. */
  7691. /**
  7692. * @cfg {Boolean} reset When set to <tt><b>true</b></tt>, causes the Form to be
  7693. * {@link Ext.form.BasicForm.reset reset} on Action success. If specified, this happens
  7694. * <b>before</b> the {@link #success} callback is called and before the Form's
  7695. * {@link Ext.form.BasicForm.actioncomplete actioncomplete} event fires.
  7696. */
  7697. /**
  7698. * @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the
  7699. * {@link Ext.form.BasicForm}'s method, or if that is not specified, the underlying DOM form's method.
  7700. */
  7701. /**
  7702. * @cfg {Mixed} params <p>Extra parameter values to pass. These are added to the Form's
  7703. * {@link Ext.form.BasicForm#baseParams} and passed to the specified URL along with the Form's
  7704. * input fields.</p>
  7705. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
  7706. */
  7707. /**
  7708. * @cfg {Number} timeout The number of seconds to wait for a server response before
  7709. * failing with the {@link #failureType} as {@link #Action.CONNECT_FAILURE}. If not specified,
  7710. * defaults to the configured <tt>{@link Ext.form.BasicForm#timeout timeout}</tt> of the
  7711. * {@link Ext.form.BasicForm form}.
  7712. */
  7713. /**
  7714. * @cfg {Function} success The function to call when a valid success return packet is recieved.
  7715. * The function is passed the following parameters:<ul class="mdetail-params">
  7716. * <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
  7717. * <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. The {@link #result}
  7718. * property of this object may be examined to perform custom postprocessing.</div></li>
  7719. * </ul>
  7720. */
  7721. /**
  7722. * @cfg {Function} failure The function to call when a failure packet was recieved, or when an
  7723. * error ocurred in the Ajax communication.
  7724. * The function is passed the following parameters:<ul class="mdetail-params">
  7725. * <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
  7726. * <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. If an Ajax
  7727. * error ocurred, the failure type will be in {@link #failureType}. The {@link #result}
  7728. * property of this object may be examined to perform custom postprocessing.</div></li>
  7729. * </ul>
  7730. */
  7731. /**
  7732. * @cfg {Object} scope The scope in which to call the callback functions (The <tt>this</tt> reference
  7733. * for the callback functions).
  7734. */
  7735. /**
  7736. * @cfg {String} waitMsg The message to be displayed by a call to {@link Ext.MessageBox#wait}
  7737. * during the time the action is being processed.
  7738. */
  7739. /**
  7740. * @cfg {String} waitTitle The title to be displayed by a call to {@link Ext.MessageBox#wait}
  7741. * during the time the action is being processed.
  7742. */
  7743. /**
  7744. * @cfg {Boolean} submitEmptyText If set to <tt>true</tt>, the emptyText value will be sent with the form
  7745. * when it is submitted. Defaults to <tt>true</tt>.
  7746. */
  7747. /**
  7748. * The type of action this Action instance performs.
  7749. * Currently only "submit" and "load" are supported.
  7750. * @type {String}
  7751. */
  7752. type : 'default',
  7753. /**
  7754. * The type of failure detected will be one of these: {@link #CLIENT_INVALID},
  7755. * {@link #SERVER_INVALID}, {@link #CONNECT_FAILURE}, or {@link #LOAD_FAILURE}. Usage:
  7756. * <pre><code>
  7757. var fp = new Ext.form.FormPanel({
  7758. ...
  7759. buttons: [{
  7760. text: 'Save',
  7761. formBind: true,
  7762. handler: function(){
  7763. if(fp.getForm().isValid()){
  7764. fp.getForm().submit({
  7765. url: 'form-submit.php',
  7766. waitMsg: 'Submitting your data...',
  7767. success: function(form, action){
  7768. // server responded with success = true
  7769. var result = action.{@link #result};
  7770. },
  7771. failure: function(form, action){
  7772. if (action.{@link #failureType} === Ext.form.Action.{@link #CONNECT_FAILURE}) {
  7773. Ext.Msg.alert('Error',
  7774. 'Status:'+action.{@link #response}.status+': '+
  7775. action.{@link #response}.statusText);
  7776. }
  7777. if (action.failureType === Ext.form.Action.{@link #SERVER_INVALID}){
  7778. // server responded with success = false
  7779. Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
  7780. }
  7781. }
  7782. });
  7783. }
  7784. }
  7785. },{
  7786. text: 'Reset',
  7787. handler: function(){
  7788. fp.getForm().reset();
  7789. }
  7790. }]
  7791. * </code></pre>
  7792. * @property failureType
  7793. * @type {String}
  7794. */
  7795. /**
  7796. * The XMLHttpRequest object used to perform the action.
  7797. * @property response
  7798. * @type {Object}
  7799. */
  7800. /**
  7801. * The decoded response object containing a boolean <tt style="font-weight:bold">success</tt> property and
  7802. * other, action-specific properties.
  7803. * @property result
  7804. * @type {Object}
  7805. */
  7806. // interface method
  7807. run : function(options){
  7808. },
  7809. // interface method
  7810. success : function(response){
  7811. },
  7812. // interface method
  7813. handleResponse : function(response){
  7814. },
  7815. // default connection failure
  7816. failure : function(response){
  7817. this.response = response;
  7818. this.failureType = Ext.form.Action.CONNECT_FAILURE;
  7819. this.form.afterAction(this, false);
  7820. },
  7821. // private
  7822. // shared code among all Actions to validate that there was a response
  7823. // with either responseText or responseXml
  7824. processResponse : function(response){
  7825. this.response = response;
  7826. if(!response.responseText && !response.responseXML){
  7827. return true;
  7828. }
  7829. this.result = this.handleResponse(response);
  7830. return this.result;
  7831. },
  7832. // utility functions used internally
  7833. getUrl : function(appendParams){
  7834. var url = this.options.url || this.form.url || this.form.el.dom.action;
  7835. if(appendParams){
  7836. var p = this.getParams();
  7837. if(p){
  7838. url = Ext.urlAppend(url, p);
  7839. }
  7840. }
  7841. return url;
  7842. },
  7843. // private
  7844. getMethod : function(){
  7845. return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
  7846. },
  7847. // private
  7848. getParams : function(){
  7849. var bp = this.form.baseParams;
  7850. var p = this.options.params;
  7851. if(p){
  7852. if(typeof p == "object"){
  7853. p = Ext.urlEncode(Ext.applyIf(p, bp));
  7854. }else if(typeof p == 'string' && bp){
  7855. p += '&' + Ext.urlEncode(bp);
  7856. }
  7857. }else if(bp){
  7858. p = Ext.urlEncode(bp);
  7859. }
  7860. return p;
  7861. },
  7862. // private
  7863. createCallback : function(opts){
  7864. var opts = opts || {};
  7865. return {
  7866. success: this.success,
  7867. failure: this.failure,
  7868. scope: this,
  7869. timeout: (opts.timeout*1000) || (this.form.timeout*1000),
  7870. upload: this.form.fileUpload ? this.success : undefined
  7871. };
  7872. }
  7873. };
  7874. /**
  7875. * @class Ext.form.Action.Submit
  7876. * @extends Ext.form.Action
  7877. * <p>A class which handles submission of data from {@link Ext.form.BasicForm Form}s
  7878. * and processes the returned response.</p>
  7879. * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  7880. * {@link Ext.form.BasicForm#submit submit}ting.</p>
  7881. * <p><u><b>Response Packet Criteria</b></u></p>
  7882. * <p>A response packet may contain:
  7883. * <div class="mdetail-params"><ul>
  7884. * <li><b><code>success</code></b> property : Boolean
  7885. * <div class="sub-desc">The <code>success</code> property is required.</div></li>
  7886. * <li><b><code>errors</code></b> property : Object
  7887. * <div class="sub-desc"><div class="sub-desc">The <code>errors</code> property,
  7888. * which is optional, contains error messages for invalid fields.</div></li>
  7889. * </ul></div>
  7890. * <p><u><b>JSON Packets</b></u></p>
  7891. * <p>By default, response packets are assumed to be JSON, so a typical response
  7892. * packet may look like this:</p><pre><code>
  7893. {
  7894. success: false,
  7895. errors: {
  7896. clientCode: "Client not found",
  7897. portOfLoading: "This field must not be null"
  7898. }
  7899. }</code></pre>
  7900. * <p>Other data may be placed into the response for processing by the {@link Ext.form.BasicForm}'s callback
  7901. * or event handler methods. The object decoded from this JSON is available in the
  7902. * {@link Ext.form.Action#result result} property.</p>
  7903. * <p>Alternatively, if an {@link #errorReader} is specified as an {@link Ext.data.XmlReader XmlReader}:</p><pre><code>
  7904. errorReader: new Ext.data.XmlReader({
  7905. record : 'field',
  7906. success: '@success'
  7907. }, [
  7908. 'id', 'msg'
  7909. ]
  7910. )
  7911. </code></pre>
  7912. * <p>then the results may be sent back in XML format:</p><pre><code>
  7913. &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  7914. &lt;message success="false"&gt;
  7915. &lt;errors&gt;
  7916. &lt;field&gt;
  7917. &lt;id&gt;clientCode&lt;/id&gt;
  7918. &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;
  7919. &lt;/field&gt;
  7920. &lt;field&gt;
  7921. &lt;id&gt;portOfLoading&lt;/id&gt;
  7922. &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;
  7923. &lt;/field&gt;
  7924. &lt;/errors&gt;
  7925. &lt;/message&gt;
  7926. </code></pre>
  7927. * <p>Other elements may be placed into the response XML for processing by the {@link Ext.form.BasicForm}'s callback
  7928. * or event handler methods. The XML document is available in the {@link #errorReader}'s {@link Ext.data.XmlReader#xmlData xmlData} property.</p>
  7929. */
  7930. Ext.form.Action.Submit = function(form, options){
  7931. Ext.form.Action.Submit.superclass.constructor.call(this, form, options);
  7932. };
  7933. Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
  7934. /**
  7935. * @cfg {Ext.data.DataReader} errorReader <p><b>Optional. JSON is interpreted with
  7936. * no need for an errorReader.</b></p>
  7937. * <p>A Reader which reads a single record from the returned data. The DataReader's
  7938. * <b>success</b> property specifies how submission success is determined. The Record's
  7939. * data provides the error messages to apply to any invalid form Fields.</p>
  7940. */
  7941. /**
  7942. * @cfg {boolean} clientValidation Determines whether a Form's fields are validated
  7943. * in a final call to {@link Ext.form.BasicForm#isValid isValid} prior to submission.
  7944. * Pass <tt>false</tt> in the Form's submit options to prevent this. If not defined, pre-submission field validation
  7945. * is performed.
  7946. */
  7947. type : 'submit',
  7948. // private
  7949. run : function(){
  7950. var o = this.options,
  7951. method = this.getMethod(),
  7952. isGet = method == 'GET';
  7953. if(o.clientValidation === false || this.form.isValid()){
  7954. if (o.submitEmptyText === false) {
  7955. var fields = this.form.items,
  7956. emptyFields = [],
  7957. setupEmptyFields = function(f){
  7958. if (f.el.getValue() == f.emptyText) {
  7959. emptyFields.push(f);
  7960. f.el.dom.value = "";
  7961. }
  7962. if(f.isComposite && f.rendered){
  7963. f.items.each(setupEmptyFields);
  7964. }
  7965. };
  7966. fields.each(setupEmptyFields);
  7967. }
  7968. Ext.Ajax.request(Ext.apply(this.createCallback(o), {
  7969. form:this.form.el.dom,
  7970. url:this.getUrl(isGet),
  7971. method: method,
  7972. headers: o.headers,
  7973. params:!isGet ? this.getParams() : null,
  7974. isUpload: this.form.fileUpload
  7975. }));
  7976. if (o.submitEmptyText === false) {
  7977. Ext.each(emptyFields, function(f) {
  7978. if (f.applyEmptyText) {
  7979. f.applyEmptyText();
  7980. }
  7981. });
  7982. }
  7983. }else if (o.clientValidation !== false){ // client validation failed
  7984. this.failureType = Ext.form.Action.CLIENT_INVALID;
  7985. this.form.afterAction(this, false);
  7986. }
  7987. },
  7988. // private
  7989. success : function(response){
  7990. var result = this.processResponse(response);
  7991. if(result === true || result.success){
  7992. this.form.afterAction(this, true);
  7993. return;
  7994. }
  7995. if(result.errors){
  7996. this.form.markInvalid(result.errors);
  7997. }
  7998. this.failureType = Ext.form.Action.SERVER_INVALID;
  7999. this.form.afterAction(this, false);
  8000. },
  8001. // private
  8002. handleResponse : function(response){
  8003. if(this.form.errorReader){
  8004. var rs = this.form.errorReader.read(response);
  8005. var errors = [];
  8006. if(rs.records){
  8007. for(var i = 0, len = rs.records.length; i < len; i++) {
  8008. var r = rs.records[i];
  8009. errors[i] = r.data;
  8010. }
  8011. }
  8012. if(errors.length < 1){
  8013. errors = null;
  8014. }
  8015. return {
  8016. success : rs.success,
  8017. errors : errors
  8018. };
  8019. }
  8020. return Ext.decode(response.responseText);
  8021. }
  8022. });
  8023. /**
  8024. * @class Ext.form.Action.Load
  8025. * @extends Ext.form.Action
  8026. * <p>A class which handles loading of data from a server into the Fields of an {@link Ext.form.BasicForm}.</p>
  8027. * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  8028. * {@link Ext.form.BasicForm#load load}ing.</p>
  8029. * <p><u><b>Response Packet Criteria</b></u></p>
  8030. * <p>A response packet <b>must</b> contain:
  8031. * <div class="mdetail-params"><ul>
  8032. * <li><b><code>success</code></b> property : Boolean</li>
  8033. * <li><b><code>data</code></b> property : Object</li>
  8034. * <div class="sub-desc">The <code>data</code> property contains the values of Fields to load.
  8035. * The individual value object for each Field is passed to the Field's
  8036. * {@link Ext.form.Field#setValue setValue} method.</div></li>
  8037. * </ul></div>
  8038. * <p><u><b>JSON Packets</b></u></p>
  8039. * <p>By default, response packets are assumed to be JSON, so for the following form load call:<pre><code>
  8040. var myFormPanel = new Ext.form.FormPanel({
  8041. title: 'Client and routing info',
  8042. items: [{
  8043. fieldLabel: 'Client',
  8044. name: 'clientName'
  8045. }, {
  8046. fieldLabel: 'Port of loading',
  8047. name: 'portOfLoading'
  8048. }, {
  8049. fieldLabel: 'Port of discharge',
  8050. name: 'portOfDischarge'
  8051. }]
  8052. });
  8053. myFormPanel.{@link Ext.form.FormPanel#getForm getForm}().{@link Ext.form.BasicForm#load load}({
  8054. url: '/getRoutingInfo.php',
  8055. params: {
  8056. consignmentRef: myConsignmentRef
  8057. },
  8058. failure: function(form, action) {
  8059. Ext.Msg.alert("Load failed", action.result.errorMessage);
  8060. }
  8061. });
  8062. </code></pre>
  8063. * a <b>success response</b> packet may look like this:</p><pre><code>
  8064. {
  8065. success: true,
  8066. data: {
  8067. clientName: "Fred. Olsen Lines",
  8068. portOfLoading: "FXT",
  8069. portOfDischarge: "OSL"
  8070. }
  8071. }</code></pre>
  8072. * while a <b>failure response</b> packet may look like this:</p><pre><code>
  8073. {
  8074. success: false,
  8075. errorMessage: "Consignment reference not found"
  8076. }</code></pre>
  8077. * <p>Other data may be placed into the response for processing the {@link Ext.form.BasicForm Form}'s
  8078. * callback or event handler methods. The object decoded from this JSON is available in the
  8079. * {@link Ext.form.Action#result result} property.</p>
  8080. */
  8081. Ext.form.Action.Load = function(form, options){
  8082. Ext.form.Action.Load.superclass.constructor.call(this, form, options);
  8083. this.reader = this.form.reader;
  8084. };
  8085. Ext.extend(Ext.form.Action.Load, Ext.form.Action, {
  8086. // private
  8087. type : 'load',
  8088. // private
  8089. run : function(){
  8090. Ext.Ajax.request(Ext.apply(
  8091. this.createCallback(this.options), {
  8092. method:this.getMethod(),
  8093. url:this.getUrl(false),
  8094. headers: this.options.headers,
  8095. params:this.getParams()
  8096. }));
  8097. },
  8098. // private
  8099. success : function(response){
  8100. var result = this.processResponse(response);
  8101. if(result === true || !result.success || !result.data){
  8102. this.failureType = Ext.form.Action.LOAD_FAILURE;
  8103. this.form.afterAction(this, false);
  8104. return;
  8105. }
  8106. this.form.clearInvalid();
  8107. this.form.setValues(result.data);
  8108. this.form.afterAction(this, true);
  8109. },
  8110. // private
  8111. handleResponse : function(response){
  8112. if(this.form.reader){
  8113. var rs = this.form.reader.read(response);
  8114. var data = rs.records && rs.records[0] ? rs.records[0].data : null;
  8115. return {
  8116. success : rs.success,
  8117. data : data
  8118. };
  8119. }
  8120. return Ext.decode(response.responseText);
  8121. }
  8122. });
  8123. /**
  8124. * @class Ext.form.Action.DirectLoad
  8125. * @extends Ext.form.Action.Load
  8126. * <p>Provides Ext.direct support for loading form data.</p>
  8127. * <p>This example illustrates usage of Ext.Direct to <b>load</b> a form through Ext.Direct.</p>
  8128. * <pre><code>
  8129. var myFormPanel = new Ext.form.FormPanel({
  8130. // configs for FormPanel
  8131. title: 'Basic Information',
  8132. renderTo: document.body,
  8133. width: 300, height: 160,
  8134. padding: 10,
  8135. // configs apply to child items
  8136. defaults: {anchor: '100%'},
  8137. defaultType: 'textfield',
  8138. items: [{
  8139. fieldLabel: 'Name',
  8140. name: 'name'
  8141. },{
  8142. fieldLabel: 'Email',
  8143. name: 'email'
  8144. },{
  8145. fieldLabel: 'Company',
  8146. name: 'company'
  8147. }],
  8148. // configs for BasicForm
  8149. api: {
  8150. // The server-side method to call for load() requests
  8151. load: Profile.getBasicInfo,
  8152. // The server-side must mark the submit handler as a 'formHandler'
  8153. submit: Profile.updateBasicInfo
  8154. },
  8155. // specify the order for the passed params
  8156. paramOrder: ['uid', 'foo']
  8157. });
  8158. // load the form
  8159. myFormPanel.getForm().load({
  8160. // pass 2 arguments to server side getBasicInfo method (len=2)
  8161. params: {
  8162. foo: 'bar',
  8163. uid: 34
  8164. }
  8165. });
  8166. * </code></pre>
  8167. * The data packet sent to the server will resemble something like:
  8168. * <pre><code>
  8169. [
  8170. {
  8171. "action":"Profile","method":"getBasicInfo","type":"rpc","tid":2,
  8172. "data":[34,"bar"] // note the order of the params
  8173. }
  8174. ]
  8175. * </code></pre>
  8176. * The form will process a data packet returned by the server that is similar
  8177. * to the following format:
  8178. * <pre><code>
  8179. [
  8180. {
  8181. "action":"Profile","method":"getBasicInfo","type":"rpc","tid":2,
  8182. "result":{
  8183. "success":true,
  8184. "data":{
  8185. "name":"Fred Flintstone",
  8186. "company":"Slate Rock and Gravel",
  8187. "email":"fred.flintstone@slaterg.com"
  8188. }
  8189. }
  8190. }
  8191. ]
  8192. * </code></pre>
  8193. */
  8194. Ext.form.Action.DirectLoad = Ext.extend(Ext.form.Action.Load, {
  8195. constructor: function(form, opts) {
  8196. Ext.form.Action.DirectLoad.superclass.constructor.call(this, form, opts);
  8197. },
  8198. type : 'directload',
  8199. run : function(){
  8200. var args = this.getParams();
  8201. args.push(this.success, this);
  8202. this.form.api.load.apply(window, args);
  8203. },
  8204. getParams : function() {
  8205. var buf = [], o = {};
  8206. var bp = this.form.baseParams;
  8207. var p = this.options.params;
  8208. Ext.apply(o, p, bp);
  8209. var paramOrder = this.form.paramOrder;
  8210. if(paramOrder){
  8211. for(var i = 0, len = paramOrder.length; i < len; i++){
  8212. buf.push(o[paramOrder[i]]);
  8213. }
  8214. }else if(this.form.paramsAsHash){
  8215. buf.push(o);
  8216. }
  8217. return buf;
  8218. },
  8219. // Direct actions have already been processed and therefore
  8220. // we can directly set the result; Direct Actions do not have
  8221. // a this.response property.
  8222. processResponse : function(result) {
  8223. this.result = result;
  8224. return result;
  8225. },
  8226. success : function(response, trans){
  8227. if(trans.type == Ext.Direct.exceptions.SERVER){
  8228. response = {};
  8229. }
  8230. Ext.form.Action.DirectLoad.superclass.success.call(this, response);
  8231. }
  8232. });
  8233. /**
  8234. * @class Ext.form.Action.DirectSubmit
  8235. * @extends Ext.form.Action.Submit
  8236. * <p>Provides Ext.direct support for submitting form data.</p>
  8237. * <p>This example illustrates usage of Ext.Direct to <b>submit</b> a form through Ext.Direct.</p>
  8238. * <pre><code>
  8239. var myFormPanel = new Ext.form.FormPanel({
  8240. // configs for FormPanel
  8241. title: 'Basic Information',
  8242. renderTo: document.body,
  8243. width: 300, height: 160,
  8244. padding: 10,
  8245. buttons:[{
  8246. text: 'Submit',
  8247. handler: function(){
  8248. myFormPanel.getForm().submit({
  8249. params: {
  8250. foo: 'bar',
  8251. uid: 34
  8252. }
  8253. });
  8254. }
  8255. }],
  8256. // configs apply to child items
  8257. defaults: {anchor: '100%'},
  8258. defaultType: 'textfield',
  8259. items: [{
  8260. fieldLabel: 'Name',
  8261. name: 'name'
  8262. },{
  8263. fieldLabel: 'Email',
  8264. name: 'email'
  8265. },{
  8266. fieldLabel: 'Company',
  8267. name: 'company'
  8268. }],
  8269. // configs for BasicForm
  8270. api: {
  8271. // The server-side method to call for load() requests
  8272. load: Profile.getBasicInfo,
  8273. // The server-side must mark the submit handler as a 'formHandler'
  8274. submit: Profile.updateBasicInfo
  8275. },
  8276. // specify the order for the passed params
  8277. paramOrder: ['uid', 'foo']
  8278. });
  8279. * </code></pre>
  8280. * The data packet sent to the server will resemble something like:
  8281. * <pre><code>
  8282. {
  8283. "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",
  8284. "result":{
  8285. "success":true,
  8286. "id":{
  8287. "extAction":"Profile","extMethod":"updateBasicInfo",
  8288. "extType":"rpc","extTID":"6","extUpload":"false",
  8289. "name":"Aaron Conran","email":"aaron@extjs.com","company":"Ext JS, LLC"
  8290. }
  8291. }
  8292. }
  8293. * </code></pre>
  8294. * The form will process a data packet returned by the server that is similar
  8295. * to the following:
  8296. * <pre><code>
  8297. // sample success packet (batched requests)
  8298. [
  8299. {
  8300. "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":3,
  8301. "result":{
  8302. "success":true
  8303. }
  8304. }
  8305. ]
  8306. // sample failure packet (one request)
  8307. {
  8308. "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",
  8309. "result":{
  8310. "errors":{
  8311. "email":"already taken"
  8312. },
  8313. "success":false,
  8314. "foo":"bar"
  8315. }
  8316. }
  8317. * </code></pre>
  8318. * Also see the discussion in {@link Ext.form.Action.DirectLoad}.
  8319. */
  8320. Ext.form.Action.DirectSubmit = Ext.extend(Ext.form.Action.Submit, {
  8321. constructor : function(form, opts) {
  8322. Ext.form.Action.DirectSubmit.superclass.constructor.call(this, form, opts);
  8323. },
  8324. type : 'directsubmit',
  8325. // override of Submit
  8326. run : function(){
  8327. var o = this.options;
  8328. if(o.clientValidation === false || this.form.isValid()){
  8329. // tag on any additional params to be posted in the
  8330. // form scope
  8331. this.success.params = this.getParams();
  8332. this.form.api.submit(this.form.el.dom, this.success, this);
  8333. }else if (o.clientValidation !== false){ // client validation failed
  8334. this.failureType = Ext.form.Action.CLIENT_INVALID;
  8335. this.form.afterAction(this, false);
  8336. }
  8337. },
  8338. getParams : function() {
  8339. var o = {};
  8340. var bp = this.form.baseParams;
  8341. var p = this.options.params;
  8342. Ext.apply(o, p, bp);
  8343. return o;
  8344. },
  8345. // Direct actions have already been processed and therefore
  8346. // we can directly set the result; Direct Actions do not have
  8347. // a this.response property.
  8348. processResponse : function(result) {
  8349. this.result = result;
  8350. return result;
  8351. },
  8352. success : function(response, trans){
  8353. if(trans.type == Ext.Direct.exceptions.SERVER){
  8354. response = {};
  8355. }
  8356. Ext.form.Action.DirectSubmit.superclass.success.call(this, response);
  8357. }
  8358. });
  8359. Ext.form.Action.ACTION_TYPES = {
  8360. 'load' : Ext.form.Action.Load,
  8361. 'submit' : Ext.form.Action.Submit,
  8362. 'directload' : Ext.form.Action.DirectLoad,
  8363. 'directsubmit' : Ext.form.Action.DirectSubmit
  8364. };
  8365. /**
  8366. * @class Ext.form.VTypes
  8367. * <p>This is a singleton object which contains a set of commonly used field validation functions.
  8368. * The validations provided are basic and intended to be easily customizable and extended.</p>
  8369. * <p>To add custom VTypes specify the <code>{@link Ext.form.TextField#vtype vtype}</code> validation
  8370. * test function, and optionally specify any corresponding error text to display and any keystroke
  8371. * filtering mask to apply. For example:</p>
  8372. * <pre><code>
  8373. // custom Vtype for vtype:'time'
  8374. var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
  8375. Ext.apply(Ext.form.VTypes, {
  8376. // vtype validation function
  8377. time: function(val, field) {
  8378. return timeTest.test(val);
  8379. },
  8380. // vtype Text property: The error text to display when the validation function returns false
  8381. timeText: 'Not a valid time. Must be in the format "12:34 PM".',
  8382. // vtype Mask property: The keystroke filter mask
  8383. timeMask: /[\d\s:amp]/i
  8384. });
  8385. * </code></pre>
  8386. * Another example:
  8387. * <pre><code>
  8388. // custom Vtype for vtype:'IPAddress'
  8389. Ext.apply(Ext.form.VTypes, {
  8390. IPAddress: function(v) {
  8391. return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
  8392. },
  8393. IPAddressText: 'Must be a numeric IP address',
  8394. IPAddressMask: /[\d\.]/i
  8395. });
  8396. * </code></pre>
  8397. * @singleton
  8398. */
  8399. Ext.form.VTypes = function(){
  8400. // closure these in so they are only created once.
  8401. var alpha = /^[a-zA-Z_]+$/,
  8402. alphanum = /^[a-zA-Z0-9_]+$/,
  8403. email = /^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/,
  8404. url = /(((^https?)|(^ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  8405. // All these messages and functions are configurable
  8406. return {
  8407. /**
  8408. * The function used to validate email addresses. Note that this is a very basic validation -- complete
  8409. * validation per the email RFC specifications is very complex and beyond the scope of this class, although
  8410. * this function can be overridden if a more comprehensive validation scheme is desired. See the validation
  8411. * section of the <a href="http://en.wikipedia.org/wiki/E-mail_address">Wikipedia article on email addresses</a>
  8412. * for additional information. This implementation is intended to validate the following emails:<tt>
  8413. * 'barney@example.de', 'barney.rubble@example.com', 'barney-rubble@example.coop', 'barney+rubble@example.com'
  8414. * </tt>.
  8415. * @param {String} value The email address
  8416. * @return {Boolean} true if the RegExp test passed, and false if not.
  8417. */
  8418. 'email' : function(v){
  8419. return email.test(v);
  8420. },
  8421. /**
  8422. * The error text to display when the email validation function returns false. Defaults to:
  8423. * <tt>'This field should be an e-mail address in the format "user@example.com"'</tt>
  8424. * @type String
  8425. */
  8426. 'emailText' : 'This field should be an e-mail address in the format "user@example.com"',
  8427. /**
  8428. * The keystroke filter mask to be applied on email input. See the {@link #email} method for
  8429. * information about more complex email validation. Defaults to:
  8430. * <tt>/[a-z0-9_\.\-@]/i</tt>
  8431. * @type RegExp
  8432. */
  8433. 'emailMask' : /[a-z0-9_\.\-@\+]/i,
  8434. /**
  8435. * The function used to validate URLs
  8436. * @param {String} value The URL
  8437. * @return {Boolean} true if the RegExp test passed, and false if not.
  8438. */
  8439. 'url' : function(v){
  8440. return url.test(v);
  8441. },
  8442. /**
  8443. * The error text to display when the url validation function returns false. Defaults to:
  8444. * <tt>'This field should be a URL in the format "http:/'+'/www.example.com"'</tt>
  8445. * @type String
  8446. */
  8447. 'urlText' : 'This field should be a URL in the format "http:/'+'/www.example.com"',
  8448. /**
  8449. * The function used to validate alpha values
  8450. * @param {String} value The value
  8451. * @return {Boolean} true if the RegExp test passed, and false if not.
  8452. */
  8453. 'alpha' : function(v){
  8454. return alpha.test(v);
  8455. },
  8456. /**
  8457. * The error text to display when the alpha validation function returns false. Defaults to:
  8458. * <tt>'This field should only contain letters and _'</tt>
  8459. * @type String
  8460. */
  8461. 'alphaText' : 'This field should only contain letters and _',
  8462. /**
  8463. * The keystroke filter mask to be applied on alpha input. Defaults to:
  8464. * <tt>/[a-z_]/i</tt>
  8465. * @type RegExp
  8466. */
  8467. 'alphaMask' : /[a-z_]/i,
  8468. /**
  8469. * The function used to validate alphanumeric values
  8470. * @param {String} value The value
  8471. * @return {Boolean} true if the RegExp test passed, and false if not.
  8472. */
  8473. 'alphanum' : function(v){
  8474. return alphanum.test(v);
  8475. },
  8476. /**
  8477. * The error text to display when the alphanumeric validation function returns false. Defaults to:
  8478. * <tt>'This field should only contain letters, numbers and _'</tt>
  8479. * @type String
  8480. */
  8481. 'alphanumText' : 'This field should only contain letters, numbers and _',
  8482. /**
  8483. * The keystroke filter mask to be applied on alphanumeric input. Defaults to:
  8484. * <tt>/[a-z0-9_]/i</tt>
  8485. * @type RegExp
  8486. */
  8487. 'alphanumMask' : /[a-z0-9_]/i
  8488. };
  8489. }();