Skip to content
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

Fixes #1065. CJuiSliderInput is now more customizable. #1685

Closed
wants to merge 6 commits into from
Closed

Fixes #1065. CJuiSliderInput is now more customizable. #1685

wants to merge 6 commits into from

Conversation

resurtm
Copy link
Contributor

@resurtm resurtm commented Nov 10, 2012

Fixes #1065. CJuiSliderInput is now more customizable.

BC and API are okay.

Testing code:

<?php echo CHtml::beginForm(); ?>

<?php
class TestModel1 extends CFormModel
{
    public $price=150;
}
class TestModel2 extends CFormModel
{
    public $priceStart=150;
    public $priceStop=400;
}
?>

<?php $this->widget('zii.widgets.jui.CJuiSliderInput',array(
    'id'=>'slider1',
    'name'=>'price',
    'value'=>150,
    'options'=>array(
        'min'=>100,
        'max'=>500,
    ),
)); ?>
<?php $this->widget('zii.widgets.jui.CJuiSliderInput',array(
    'id'=>'slider2',
    'name'=>'priceStart',
    'value'=>150,
    'maxName'=>'priceStop',
    'maxValue'=>400,
    'options'=>array(
        'range'=>true,
        'min'=>100,
        'max'=>500,
    ),
    'idEndSuffix'=>'End',
)); ?>

<?php $this->widget('zii.widgets.jui.CJuiSliderInput',array(
    'id'=>'slider3',
    'model'=>new TestModel1(),
    'attribute'=>'price',
    'options'=>array(
        'min'=>100,
        'max'=>500,
    ),
)); ?>
<?php $this->widget('zii.widgets.jui.CJuiSliderInput',array(
    'id'=>'slider4',
    'model'=>new TestModel2(),
    'attribute'=>'priceStart',
    'maxAttribute'=>'priceStop',
    'options'=>array(
        'range'=>true,
        'min'=>100,
        'max'=>500,
    ),
    'idEndSuffix'=>'End',
)); ?>

<?php echo CHtml::submitButton(); ?>
<?php echo CHtml::endForm(); ?>

<?php
// ...

// controller action
public function actionIndex()
{
    if(Yii::app()->request->isPostRequest)
    {
        CVarDumper::dump($_POST);
        Yii::app()->end();
    }

    $this->render('index');
}

After submitting form above following ouput will happen:

array
(
    'price' => '150'
    'priceStart' => '150'
    'priceStop' => '400'
    'TestModel1' => array
    (
        'price' => '150'
    )
    'TestModel2' => array
    (
        'priceStart' => '150'
        'priceStop' => '400'
    )
    'yt0' => 'submit'
)

Generated HTML:

<form action="/" method="post">
    <input id="slider1" type="hidden" value="150" name="price" />
    <div id="slider1_slider"></div>

    <input id="slider2" type="hidden" value="150" name="priceStart" />
    <input id="slider2End" type="hidden" value="400" name="priceStop" />
    <div id="slider2_slider"></div>

    <input id="slider3" name="TestModel1[price]" type="hidden" value="150" />
    <div id="slider3_slider"></div>

    <input id="slider4" name="TestModel2[priceStart]" type="hidden" value="150" />
    <input id="slider4End" name="TestModel2[priceStop]" type="hidden" value="400" />
    <div id="slider4_slider"></div>

    <input type="submit" name="yt0" value="submit" />
</form>

Generated JS:

jQuery(function($) {
jQuery('#slider1_slider').slider({'min':100,'max':500,'value':150,'slide':function(event, ui) { jQuery('#slider1').val(ui.value); }});

jQuery('#slider2_slider').slider({'range':true,'min':100,'max':500,'values':[150,400],'slide':function(e,ui){ v=ui.values; jQuery('#slider2').val(v[0]); jQuery('#slider2End').val(v[1]); }});

jQuery('#slider3_slider').slider({'min':100,'max':500,'value':150,'slide':function(event, ui) { jQuery('#slider3').val(ui.value); }});

jQuery('#slider4_slider').slider({'range':true,'min':100,'max':500,'values':[150,400],'slide':function(e,ui){ v=ui.values; jQuery('#slider4').val(v[0]); jQuery('#slider4End').val(v[1]); }});

new CJavaScriptExpression('function(event, ui) { jQuery(\'#'. $idHidden .'\').val(ui.value); }');

$options=empty($this->options) ? '' : CJavaScript::encode($this->options);

$js = "jQuery('#{$id}_slider').slider($options);\n";
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id, $js);
Yii::app()->getClientScript()->registerScript('CJuiSliderInput#'.$id, $js);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__CLASS__ is a kind of reflection. Reflections are relatively slow, so i've removed it at all.

new CJavaScriptExpression('function(event, ui) { jQuery(\'#'. $idHidden .'\').val(ui.value); }');
$this->options[$this->event]=$isRange
? new CJavaScriptExpression("function(e,ui){ v=ui.values; jQuery('#{$idHidden}').val(v[0]); jQuery('#{$idHidden}{$this->idEndSuffix}').val(v[1]); }")
: new CJavaScriptExpression('function(event, ui) { jQuery(\'#'. $idHidden .'\').val(ui.value); }');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better readability.

@samdark
Copy link
Member

samdark commented Nov 16, 2012

Overall code looks OK. Haven't got a chance to check it in action yet.

@samdark
Copy link
Member

samdark commented May 27, 2013

@resurtm let's update strings to 1.1.14 and merge it.

@ghost ghost assigned resurtm May 31, 2013
resurtm added a commit that referenced this pull request May 31, 2013
@resurtm
Copy link
Contributor Author

resurtm commented May 31, 2013

Merged manually: d698526...b7a1d14

@resurtm resurtm closed this May 31, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CJuiSliderInput
4 participants