New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(new) CJuiDatePicker handling native datepicker events. #1238
Comments
The "js:" method is deprecated and should not be used anymore... so this part should be removed... Please explain why would we need to add the onSelect property when you can already send a custom handler with options['onSelect'] ? |
if you override the default "options['onSelect']" functionality then you must remembero to notify the new selectedDate value to the hiddenField (model / attribute case), if you forgot or misplace something then the model/attribute does not receive the selected value and modeling fails. Finally, the standard yii programmer can use this widget in a more clear and simple way instead of writing code to support the selectedDate to be passed to model.attribute. |
in respect to "js:", it is handled on widget in case the user doesn't know about deprecation. I could throw an exception if you prefer to ensure the user must not use "js:" anymore. |
"js:" is already handled by encode method so you don't need to check that at all but... I think I found here a better solution. The main point in this issue is to fill the hidden field so that developers do not need to think about it, right ? How about using the altField for this ? The solution is as simple as replacing the lines 105-106 - https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/jui/CJuiDatePicker.php#L105
with
|
Yes you're in right. the provided altField (core datepicker ui options) is there to update an extra field and not only for common ALT usage. next commit will use this field to handle the hidden field, leaving the onSelect option free for directly usage without taking care of hiddenField value. |
…pression and datepicker_altField handling hiddenField updates.
last commit ready implementing altField and a filter for onSelect, please read more about this: it works fine as: $this->widget('zii.widgets.jui.CJuiDatePicker', array( and it works fine too using CJavaScriptExpression: $this->widget('zii.widgets.jui.CJuiDatePicker', array( if the final user use or not the CJavaScriptExpression to set a handler for onSelect option then CJuiDatePicker take care of this verifying if the passed onSelect value is an instanceOf CJavaScriptExpression, if not it make it a new CJavaScriptExpression using the provided value, so the resulting script is: |
The only needed change is as I wrote it above... only one line! As I already explained before.. you don't need to check the options... all that is done already by encode method - https://github.com/christiansalazar/yii/blob/fb702a28f47f812961b6ce95f4d43a4316788730/framework/zii/widgets/jui/CJuiDatePicker.php#L136 and there is no need to add inline comments explaining the altField usage |
comment lines removed, but, in the case of onSelect option, the provided code is needed, because: if we dont process the onSelect option, this piece of code doesnt works. because CJavascript::encode() threat it as a string, producing: the way1 to make it works is: (deprecated, prepending js) the way2 to make it works (right way): but, the standard yii programmer doesnt know the way2. so, in order to help, the widget would detect if he or she is using a string or an instance of CJavascriptExpression, if is not a CJavascriptExpression then it convert the provided string into a CJavascriptExpression, so: the way3: (a pure string, now it will works fine) As a resume, processing the onSelect option now will allow this usage: |
yes, you are right for the onSelect processing... I made two comments on the latest commit.. |
…al for empty string on onSelect value.
latest commit has this change on it, plus: an extra validation for: "onSelect"=>"". needed because if this event handler is an empty string then the widget disappears. example (whitout filtering for empty string): is not the same case when passing null: so the extra validation for empty string is to avoid the javascript crash produced when CJavascript::encode outputs: nothing when it receive an instance of: new CJavaScriptExpression(""). (not same case with null, it outputs null) |
that is a developer error... why would we fix that? it would be the same for any other value or not ? |
at this point, the input test for onSelect is OK for this cases: 'onSelect'=>null, |
in respect to: "that is a developer error... why would we fix that? i think: is not an error to provide an empty string for an onSelect=>"", i think it will confuse the developper: he or she will pass hours detecting why javascript is crash, and when he or she will be wondered when discover the cause: a simple empty string. |
going more deeply, the next events will be processed in the same way as for onSelect case:
|
My point is that it would be the same for any other Yii properties that requires javascript code... and btw why would anyone set this to an empty string? The documentation for this option is very clear - http://jqueryui.com/demos/datepicker/#event-onSelect
|
let me find an existing case to verify it, |
Again... why would we do it ? what is your use-case for this? |
maurizio, looking in CGridView.selectionChanged when an empty string is provided it will crash too in same way. So, as you said, we dont fix the empty string in CJui too. |
the job of the framework is to help developers to do things faster... it's not to fix developers errors ;) |
yes you are on right. next question: supporting the same filtering for:
i think to provide a method for this. |
for that (more events) you can use this code - https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php#L1048 |
test for all datepicker events passed. |
nice. |
yes, there is no need for any special event handling as it's already handled when the JS code is used with 'js:' or 'new CJavascriptExpression' There is no need to handle the variation with pure JS code ((like you tryed) ) because in all other parts of the framework where JS code can be assigned the 'js:' (deprecated) or CJavascriptExpression (prefered) should be used. |
hello. i am trying to get selectWeek to work. can anyone help? http://stackoverflow.com/questions/26713040/cjuidatepicker-select-week |
hi shorif2000, im sure this is not the right place to put your issue. :-) also im sure this issue is closed. |
The original source provided in CJuiDatePicker uses the onSelect (datepicker native event) to pass selected date into hiddenField in order to be consistent in model/attribute scenario, but, if you try use this onSelect event for your own pruposes then you must be carefull to support the hiddenField update or your model doesnt receive the selected date.
The primary target in this commit is to separate the hiddenField update from the event onSelect, and as secondary target the commit will provide support for all event handlers found currently in datepicker jQuery component.
Yes, the current CJuiDatePicker support this events via passing it from options, but events will works only prepending "js:" in the function passed via string:
"options"=>array(
"onSelect"=>"js:myHandler(a,b){ ... }"
),
(it doesnt works if you pass: "onSelect"=>"myHandler(a,b){ ... }", without the 'js:')
the "js" is deprecated.
This commit will solve this two targets (hiddenField update and event processign):
will be updated using the altField provided by datepicker, leaving onSelect event for user defined pruposes.
2 event processing:
all events mentioned before will be processed in order to be a CJavaScriptExpression instance, instead of a simple string,
so, this cases will work fine now:
'onSelect'=>null,
'onSelect'=>"js:function(a,b){ ... }", (deprecated, but yet needed for datepicker)
'onSelect'=>"function(a,b){ ... }",
'onSelect'=>new CJavaScriptExpression("function(a,b){ ... }"),
important:
'onSelect'=>"",
will produce a javascript crash because a CJavaScript::encode(new CJavaScriptExpression("")) will produce an invalid option for datepicker.
The text was updated successfully, but these errors were encountered: