Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
Yii Bootstrap 3
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Common
Yii Bootstrap 3
Commits
491b26b9
Commit
491b26b9
authored
Mar 12, 2012
by
Crisu83
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added input addon support (fixes #23) and moved captchaOptions last
parent
5ccd3444
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
128 additions
and
42 deletions
+128
-42
Crisu.xml
.idea/dictionaries/Crisu.xml
+1
-0
TestForm.php
demo/protected/models/TestForm.php
+4
-0
main.php
demo/protected/views/layouts/main.php
+1
-0
index.php
demo/protected/views/site/index.php
+4
-0
BootActiveForm.php
widgets/BootActiveForm.php
+2
-2
BootInput.php
widgets/input/BootInput.php
+87
-28
BootInputHorizontal.php
widgets/input/BootInputHorizontal.php
+27
-12
BootInputVertical.php
widgets/input/BootInputVertical.php
+2
-0
No files found.
.idea/dictionaries/Crisu.xml
View file @
491b26b9
...
...
@@ -6,6 +6,7 @@
<w>
navbar
</w>
<w>
scrollspy
</w>
<w>
tabbable
</w>
<w>
uneditable
</w>
<w>
unstyled
</w>
</words>
</dictionary>
...
...
demo/protected/models/TestForm.php
View file @
491b26b9
...
...
@@ -15,6 +15,8 @@ class TestForm extends CFormModel
public
$fileField
;
public
$uneditable
;
public
$disabled
;
public
$prepend
;
public
$append
;
public
$disabledCheckbox
;
public
$captcha
;
...
...
@@ -30,6 +32,8 @@ class TestForm extends CFormModel
'fileField'
=>
'File input'
,
'uneditable'
=>
'Uneditable input'
,
'disabled'
=>
'Disabled input'
,
'prepend'
=>
'Prepend text'
,
'append'
=>
'Append text'
,
'disabledCheckbox'
=>
'Disabled checkbox'
,
);
}
...
...
demo/protected/views/layouts/main.php
View file @
491b26b9
...
...
@@ -76,6 +76,7 @@
array
(
'class'
=>
'bootstrap.widgets.BootMenu'
,
'items'
=>
array
(
array
(
'label'
=>
'Bootstrap Docs'
,
'url'
=>
'http://twitter.github.com/bootstrap'
,
'linkOptions'
=>
array
(
'target'
=>
'_blank'
)),
array
(
'label'
=>
'Fork me on Bitbucket'
,
'url'
=>
'http://www.bitbucket.org/Crisu83/yii-bootstrap'
,
'linkOptions'
=>
array
(
'target'
=>
'_blank'
)),
array
(
'label'
=>
'Follow me on Twitter'
,
'url'
=>
'http://www.twitter.com/Crisu83'
,
'linkOptions'
=>
array
(
'target'
=>
'_blank'
)),
),
...
...
demo/protected/views/site/index.php
View file @
491b26b9
...
...
@@ -724,6 +724,8 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php
echo
$form
->
textAreaRow
(
$model
,
'textarea'
,
array
(
'class'
=>
'span8'
,
'rows'
=>
5
));
?>
<?php
echo
$form
->
uneditableRow
(
$model
,
'uneditable'
);
?>
<?php
echo
$form
->
textFieldRow
(
$model
,
'disabled'
,
array
(
'disabled'
=>
true
));
?>
<?php
echo
$form
->
textFieldRow
(
$model
,
'prepend'
,
array
(
'prepend'
=>
'@'
,
'hint'
=>
'Coming in version 0.9.10'
));
?>
<?php
echo
$form
->
textFieldRow
(
$model
,
'append'
,
array
(
'append'
=>
'.00'
,
'hint'
=>
'Coming in version 0.9.10'
));
?>
<?php
echo
$form
->
checkBoxRow
(
$model
,
'disabledCheckbox'
,
array
(
'disabled'
=>
true
));
?>
<?php
echo
$form
->
checkBoxListInlineRow
(
$model
,
'inlineCheckboxes'
,
array
(
'1'
,
'2'
,
'3'
));
?>
<?php
echo
$form
->
checkBoxListRow
(
$model
,
'checkboxes'
,
array
(
...
...
@@ -811,6 +813,8 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php echo
\$
form->textAreaRow(
\$
model, 'textarea', array('class'=>'span8', 'rows'=>5)); ?>
<?php echo
\$
form->uneditableRow(
\$
model, 'uneditable'); ?>
<?php echo
\$
form->textFieldRow(
\$
model, 'disabled', array('disabled'=>true)); ?>
<?php echo
\$
form->textFieldRow(
\$
model, 'prepend', array('prepend'=>'@', 'hint'=>'Coming in version 0.9.10')); ?>
<?php echo
\$
form->textFieldRow(
\$
model, 'append', array('append'=>'.00', 'hint'=>'Coming in version 0.9.10')); ?>
<?php echo
\$
form->checkBoxRow(
\$
model, 'disabledCheckbox', array('disabled'=>true)); ?>
<?php echo
\$
form->checkBoxListInlineRow(
\$
model, 'inlineCheckboxes', array('1', '2', '3')); ?>
<?php echo
\$
form->checkBoxListRow(
\$
model, 'checkboxes', array(
...
...
widgets/BootActiveForm.php
View file @
491b26b9
...
...
@@ -196,12 +196,12 @@ class BootActiveForm extends CActiveForm
* Renders a captcha row.
* @param CModel $model the data model
* @param string $attribute the attribute
* @param array $captchaOptions the captcha options
* @param array $htmlOptions additional HTML attributes
* @param array $captchaOptions the captcha options
* @return string the generated row
* @since 0.9.3
*/
public
function
captchaRow
(
$model
,
$attribute
,
$
captchaOptions
=
array
(),
$html
Options
=
array
())
public
function
captchaRow
(
$model
,
$attribute
,
$
htmlOptions
=
array
(),
$captcha
Options
=
array
())
{
return
$this
->
inputRow
(
BootInput
::
TYPE_CAPTCHA
,
$model
,
$attribute
,
$captchaOptions
,
$htmlOptions
);
}
...
...
widgets/input/BootInput.php
View file @
491b26b9
...
...
@@ -53,14 +53,23 @@ abstract class BootInput extends CInputWidget
*/
public
function
init
()
{
if
(
$this
->
form
===
null
)
if
(
!
isset
(
$this
->
form
)
)
throw
new
CException
(
__CLASS__
.
': Failed to initialize widget! Form is not set.'
);
if
(
$this
->
model
===
null
)
if
(
!
isset
(
$this
->
model
)
)
throw
new
CException
(
__CLASS__
.
': Failed to initialize widget! Model is not set.'
);
if
(
$this
->
type
===
null
)
if
(
!
isset
(
$this
->
type
)
)
throw
new
CException
(
__CLASS__
.
': Failed to initialize widget! Input type is not set.'
);
if
(
$this
->
type
===
self
::
TYPE_UNEDITABLE
)
{
$cssClass
=
'uneditable-input'
;
if
(
isset
(
$this
->
htmlOptions
[
'class'
]))
$this
->
htmlOptions
[
'class'
]
.=
' '
.
$cssClass
;
else
$this
->
htmlOptions
[
'class'
]
=
$cssClass
;
}
}
/**
...
...
@@ -120,12 +129,6 @@ abstract class BootInput extends CInputWidget
break
;
case
self
::
TYPE_UNEDITABLE
:
$cssClass
=
'uneditable-input'
;
if
(
isset
(
$this
->
htmlOptions
[
'class'
]))
$this
->
htmlOptions
[
'class'
]
.=
' '
.
$cssClass
;
else
$this
->
htmlOptions
[
'class'
]
=
$cssClass
;
$this
->
uneditableField
();
break
;
...
...
@@ -135,27 +138,86 @@ abstract class BootInput extends CInputWidget
}
/**
* Returns the
error text
for the input.
* Returns the
label
for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the
error text
* @return string the
label
*/
protected
function
get
Error
(
$htmlOptions
=
array
())
protected
function
get
Label
(
$htmlOptions
=
array
())
{
return
$this
->
form
->
error
(
$this
->
model
,
$this
->
attribute
,
$htmlOptions
);
if
(
$this
->
label
!==
false
&&
!
in_array
(
$this
->
type
,
array
(
'checkbox'
,
'radio'
))
&&
$this
->
hasModel
())
return
$this
->
form
->
labelEx
(
$this
->
model
,
$this
->
attribute
,
$htmlOptions
);
else
if
(
$this
->
label
!==
null
)
return
$this
->
label
;
else
return
''
;
}
/**
* Returns the container CSS class for the input.
* @return string the CSS class.
*/
protected
function
getContainerCssClass
()
protected
function
getPrepend
(
$htmlOptions
=
array
())
{
if
(
$this
->
model
->
hasErrors
(
$this
->
attribute
))
return
CHtml
::
$errorCss
;
if
(
$this
->
hasAddOn
())
{
$cssClass
=
'add-on'
;
if
(
isset
(
$htmlOptions
[
'class'
]))
$htmlOptions
[
'class'
]
.=
' '
.
$cssClass
;
else
$htmlOptions
[
'class'
]
=
$cssClass
;
$cssClass
=
$this
->
getInputContainerCssClass
();
ob_start
();
echo
'<div class="'
.
$cssClass
.
'">'
;
if
(
isset
(
$this
->
htmlOptions
[
'prepend'
]))
echo
CHtml
::
tag
(
'span'
,
$htmlOptions
,
$this
->
htmlOptions
[
'prepend'
]);
return
ob_get_clean
();
}
else
return
''
;
}
protected
function
getAppend
(
$htmlOptions
=
array
())
{
if
(
$this
->
hasAddOn
())
{
$cssClass
=
'add-on'
;
if
(
isset
(
$htmlOptions
[
'class'
]))
$htmlOptions
[
'class'
]
.=
' '
.
$cssClass
;
else
$htmlOptions
[
'class'
]
=
$cssClass
;
ob_start
();
if
(
isset
(
$this
->
htmlOptions
[
'append'
]))
echo
CHtml
::
tag
(
'span'
,
$htmlOptions
,
$this
->
htmlOptions
[
'append'
]);
echo
'</div>'
;
return
ob_get_clean
();
}
else
return
''
;
}
protected
function
getInputContainerCssClass
()
{
if
(
isset
(
$this
->
htmlOptions
[
'prepend'
]))
return
'input-prepend'
;
else
if
(
isset
(
$this
->
htmlOptions
[
'append'
]))
return
'input-append'
;
else
return
''
;
}
protected
function
hasAddOn
()
{
return
isset
(
$this
->
htmlOptions
[
'prepend'
])
||
isset
(
$this
->
htmlOptions
[
'append'
]);
}
/**
* Returns the error text for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the error text
*/
protected
function
getError
(
$htmlOptions
=
array
())
{
return
$this
->
form
->
error
(
$this
->
model
,
$this
->
attribute
,
$htmlOptions
);
}
/**
* Returns the hint text for the input.
* @return string the hint text
...
...
@@ -173,16 +235,13 @@ abstract class BootInput extends CInputWidget
}
/**
* Returns the label for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the label
* Returns the container CSS class for the input.
* @return string the CSS class.
*/
protected
function
get
Label
(
$htmlOptions
=
array
()
)
protected
function
get
ContainerCssClass
(
)
{
if
(
$this
->
label
!==
false
&&
!
in_array
(
$this
->
type
,
array
(
'checkbox'
,
'radio'
))
&&
$this
->
hasModel
())
return
$this
->
form
->
labelEx
(
$this
->
model
,
$this
->
attribute
,
$htmlOptions
);
else
if
(
$this
->
label
!==
null
)
return
$this
->
label
;
if
(
$this
->
model
->
hasErrors
(
$this
->
attribute
))
return
CHtml
::
$errorCss
;
else
return
''
;
}
...
...
widgets/input/BootInputHorizontal.php
View file @
491b26b9
...
...
@@ -20,8 +20,7 @@ class BootInputHorizontal extends BootInput
*/
public
function
run
()
{
$cssClass
=
$this
->
getContainerCssClass
();
echo
CHtml
::
openTag
(
'div'
,
array
(
'class'
=>
'control-group '
.
$cssClass
));
echo
CHtml
::
openTag
(
'div'
,
array
(
'class'
=>
'control-group '
.
$this
->
getContainerCssClass
()));
parent
::
run
();
echo
'</div>'
;
}
...
...
@@ -33,7 +32,12 @@ class BootInputHorizontal extends BootInput
*/
protected
function
getLabel
(
$htmlOptions
=
array
())
{
$htmlOptions
[
'class'
]
=
'control-label'
;
$cssClass
=
'control-label'
;
if
(
isset
(
$htmlOptions
[
'class'
]))
$htmlOptions
[
'class'
]
.=
' '
.
$cssClass
;
else
$htmlOptions
[
'class'
]
=
$cssClass
;
return
parent
::
getLabel
(
$htmlOptions
);
}
...
...
@@ -57,7 +61,8 @@ class BootInputHorizontal extends BootInput
*/
protected
function
checkBoxList
()
{
echo
$this
->
getLabel
()
.
'<div class="controls">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls">'
;
echo
$this
->
form
->
checkBoxList
(
$this
->
model
,
$this
->
attribute
,
$this
->
data
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
...
...
@@ -79,7 +84,8 @@ class BootInputHorizontal extends BootInput
*/
protected
function
dropDownList
()
{
echo
$this
->
getLabel
()
.
'<div class="controls">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls">'
;
echo
$this
->
form
->
dropDownList
(
$this
->
model
,
$this
->
attribute
,
$this
->
data
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
...
...
@@ -91,7 +97,8 @@ class BootInputHorizontal extends BootInput
*/
protected
function
fileField
()
{
echo
$this
->
getLabel
()
.
'<div class="controls">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls">'
;
echo
$this
->
form
->
fileField
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
...
...
@@ -103,7 +110,8 @@ class BootInputHorizontal extends BootInput
*/
protected
function
passwordField
()
{
echo
$this
->
getLabel
()
.
'<div class="controls">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls">'
;
echo
$this
->
form
->
passwordField
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
...
...
@@ -129,7 +137,8 @@ class BootInputHorizontal extends BootInput
*/
protected
function
radioButtonList
()
{
echo
$this
->
getLabel
()
.
'<div class="controls">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls">'
;
echo
$this
->
form
->
radioButtonList
(
$this
->
model
,
$this
->
attribute
,
$this
->
data
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
...
...
@@ -151,7 +160,8 @@ class BootInputHorizontal extends BootInput
*/
protected
function
textArea
()
{
echo
$this
->
getLabel
()
.
'<div class="controls">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls">'
;
echo
$this
->
form
->
textArea
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
...
...
@@ -163,8 +173,11 @@ class BootInputHorizontal extends BootInput
*/
protected
function
textField
()
{
echo
$this
->
getLabel
()
.
'<div class="controls">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls">'
;
echo
$this
->
getPrepend
();
echo
$this
->
form
->
textField
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
getAppend
();
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
}
...
...
@@ -175,7 +188,8 @@ class BootInputHorizontal extends BootInput
*/
protected
function
captcha
()
{
echo
$this
->
getLabel
()
.
'<div class="controls"><div class="captcha">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls"><div class="captcha">'
;
echo
'<div class="widget">'
.
$this
->
widget
(
'CCaptcha'
,
$this
->
data
,
true
)
.
'</div>'
;
echo
$this
->
form
->
textField
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
...
...
@@ -188,7 +202,8 @@ class BootInputHorizontal extends BootInput
*/
protected
function
uneditableField
()
{
echo
$this
->
getLabel
()
.
'<div class="controls">'
;
echo
$this
->
getLabel
();
echo
'<div class="controls">'
;
echo
CHtml
::
tag
(
'span'
,
$this
->
htmlOptions
,
$this
->
model
->
{
$this
->
attribute
});
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
...
...
widgets/input/BootInputVertical.php
View file @
491b26b9
...
...
@@ -147,7 +147,9 @@ class BootInputVertical extends BootInput
protected
function
textField
()
{
echo
$this
->
getLabel
();
echo
$this
->
getPrepend
();
echo
$this
->
form
->
textField
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
getAppend
();
echo
$this
->
getError
()
.
$this
->
getHint
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment