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
bc8704c3
Commit
bc8704c3
authored
May 13, 2012
by
Crisu83
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for setting htmlOptions for each form element
parent
d912b1e8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
68 deletions
+129
-68
BootActiveForm.php
widgets/BootActiveForm.php
+2
-3
BootInput.php
widgets/input/BootInput.php
+106
-43
BootInputHorizontal.php
widgets/input/BootInputHorizontal.php
+8
-9
BootInputVertical.php
widgets/input/BootInputVertical.php
+13
-13
No files found.
widgets/BootActiveForm.php
View file @
bc8704c3
...
@@ -200,13 +200,12 @@ class BootActiveForm extends CActiveForm
...
@@ -200,13 +200,12 @@ class BootActiveForm extends CActiveForm
* @param CModel $model the data model
* @param CModel $model the data model
* @param string $attribute the attribute
* @param string $attribute the attribute
* @param array $htmlOptions additional HTML attributes
* @param array $htmlOptions additional HTML attributes
* @param array $captchaOptions the captcha options
* @return string the generated row
* @return string the generated row
* @since 0.9.3
* @since 0.9.3
*/
*/
public
function
captchaRow
(
$model
,
$attribute
,
$htmlOptions
=
array
()
,
$captchaOptions
=
array
()
)
public
function
captchaRow
(
$model
,
$attribute
,
$htmlOptions
=
array
())
{
{
return
$this
->
inputRow
(
BootInput
::
TYPE_CAPTCHA
,
$model
,
$attribute
,
$
captchaOptions
,
$
htmlOptions
);
return
$this
->
inputRow
(
BootInput
::
TYPE_CAPTCHA
,
$model
,
$attribute
,
$htmlOptions
);
}
}
/**
/**
...
...
widgets/input/BootInput.php
View file @
bc8704c3
...
@@ -64,11 +64,10 @@ abstract class BootInput extends CInputWidget
...
@@ -64,11 +64,10 @@ abstract class BootInput extends CInputWidget
if
(
$this
->
type
===
self
::
TYPE_UNEDITABLE
)
if
(
$this
->
type
===
self
::
TYPE_UNEDITABLE
)
{
{
$classes
=
'uneditable-input'
;
if
(
isset
(
$this
->
htmlOptions
[
'class'
]))
if
(
isset
(
$this
->
htmlOptions
[
'class'
]))
$this
->
htmlOptions
[
'class'
]
.=
'
'
.
$classes
;
$this
->
htmlOptions
[
'class'
]
.=
'
uneditable-input'
;
else
else
$this
->
htmlOptions
[
'class'
]
=
$classes
;
$this
->
htmlOptions
[
'class'
]
=
'uneditable-input'
;
}
}
}
}
...
@@ -139,11 +138,18 @@ abstract class BootInput extends CInputWidget
...
@@ -139,11 +138,18 @@ abstract class BootInput extends CInputWidget
/**
/**
* Returns the label for the input.
* Returns the label for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the label
* @return string the label
*/
*/
protected
function
getLabel
(
$htmlOptions
=
array
()
)
protected
function
getLabel
()
{
{
if
(
isset
(
$this
->
htmlOptions
[
'labelOptions'
]))
{
$htmlOptions
=
$this
->
htmlOptions
[
'labelOptions'
];
unset
(
$this
->
htmlOptions
[
'labelOptions'
]);
}
else
$htmlOptions
=
array
();
if
(
$this
->
label
!==
false
&&
!
in_array
(
$this
->
type
,
array
(
'checkbox'
,
'radio'
))
&&
$this
->
hasModel
())
if
(
$this
->
label
!==
false
&&
!
in_array
(
$this
->
type
,
array
(
'checkbox'
,
'radio'
))
&&
$this
->
hasModel
())
return
$this
->
form
->
labelEx
(
$this
->
model
,
$this
->
attribute
,
$htmlOptions
);
return
$this
->
form
->
labelEx
(
$this
->
model
,
$this
->
attribute
,
$htmlOptions
);
else
if
(
$this
->
label
!==
null
)
else
if
(
$this
->
label
!==
null
)
...
@@ -154,24 +160,33 @@ abstract class BootInput extends CInputWidget
...
@@ -154,24 +160,33 @@ abstract class BootInput extends CInputWidget
/**
/**
* Returns the prepend element for the input.
* Returns the prepend element for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the element
* @return string the element
*/
*/
protected
function
getPrepend
(
$htmlOptions
=
array
()
)
protected
function
getPrepend
()
{
{
if
(
$this
->
hasAddOn
())
if
(
$this
->
hasAddOn
())
{
{
$classes
=
'add-on'
;
if
(
isset
(
$this
->
htmlOptions
[
'prependOptions'
]))
{
$htmlOptions
=
$this
->
htmlOptions
[
'prependOptions'
];
unset
(
$this
->
htmlOptions
[
'prependOptions'
]);
}
else
$htmlOptions
=
array
();
if
(
isset
(
$htmlOptions
[
'class'
]))
if
(
isset
(
$htmlOptions
[
'class'
]))
$htmlOptions
[
'class'
]
.=
'
'
.
$classes
;
$htmlOptions
[
'class'
]
.=
'
add-on'
;
else
else
$htmlOptions
[
'class'
]
=
$classes
;
$htmlOptions
[
'class'
]
=
'add-on'
;
$classes
=
$this
->
getInputContainerCssClass
();
$classes
=
$this
->
getInputContainerCssClass
();
ob_start
();
ob_start
();
echo
'<div class="'
.
$classes
.
'">'
;
echo
'<div class="'
.
$classes
.
'">'
;
if
(
isset
(
$this
->
htmlOptions
[
'prepend'
]))
if
(
isset
(
$this
->
htmlOptions
[
'prepend'
]))
{
echo
CHtml
::
tag
(
'span'
,
$htmlOptions
,
$this
->
htmlOptions
[
'prepend'
]);
echo
CHtml
::
tag
(
'span'
,
$htmlOptions
,
$this
->
htmlOptions
[
'prepend'
]);
unset
(
$this
->
htmlOptions
[
'prepend'
]);
}
return
ob_get_clean
();
return
ob_get_clean
();
}
}
else
else
...
@@ -180,22 +195,31 @@ abstract class BootInput extends CInputWidget
...
@@ -180,22 +195,31 @@ abstract class BootInput extends CInputWidget
/**
/**
* Returns the append element for the input.
* Returns the append element for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the element
* @return string the element
*/
*/
protected
function
getAppend
(
$htmlOptions
=
array
()
)
protected
function
getAppend
()
{
{
if
(
$this
->
hasAddOn
())
if
(
$this
->
hasAddOn
())
{
{
$classes
=
'add-on'
;
if
(
isset
(
$this
->
htmlOptions
[
'appendOptions'
]))
{
$htmlOptions
=
$this
->
htmlOptions
[
'appendOptions'
];
unset
(
$this
->
htmlOptions
[
'appendOptions'
]);
}
else
$htmlOptions
=
array
();
if
(
isset
(
$htmlOptions
[
'class'
]))
if
(
isset
(
$htmlOptions
[
'class'
]))
$htmlOptions
[
'class'
]
.=
'
'
.
$classes
;
$htmlOptions
[
'class'
]
.=
'
add-on'
;
else
else
$htmlOptions
[
'class'
]
=
$classes
;
$htmlOptions
[
'class'
]
=
'add-on'
;
ob_start
();
ob_start
();
if
(
isset
(
$this
->
htmlOptions
[
'append'
]))
if
(
isset
(
$this
->
htmlOptions
[
'append'
]))
{
echo
CHtml
::
tag
(
'span'
,
$htmlOptions
,
$this
->
htmlOptions
[
'append'
]);
echo
CHtml
::
tag
(
'span'
,
$htmlOptions
,
$this
->
htmlOptions
[
'append'
]);
unset
(
$this
->
htmlOptions
[
'append'
]);
}
echo
'</div>'
;
echo
'</div>'
;
return
ob_get_clean
();
return
ob_get_clean
();
}
}
...
@@ -216,36 +240,19 @@ abstract class BootInput extends CInputWidget
...
@@ -216,36 +240,19 @@ abstract class BootInput extends CInputWidget
}
}
/**
/**
* Returns the input container CSS classes.
* @return string the classes
*/
protected
function
getInputContainerCssClass
()
{
$classes
=
array
();
if
(
isset
(
$this
->
htmlOptions
[
'prepend'
]))
$classes
[]
=
'input-prepend'
;
if
(
isset
(
$this
->
htmlOptions
[
'append'
]))
$classes
[]
=
'input-append'
;
return
implode
(
' '
,
$classes
);
}
/**
* Returns whether the input has an add-on (prepend and/or append).
* @return boolean the result
*/
protected
function
hasAddOn
()
{
return
isset
(
$this
->
htmlOptions
[
'prepend'
])
||
isset
(
$this
->
htmlOptions
[
'append'
]);
}
/**
* Returns the error text for the input.
* Returns the error text for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the error text
* @return string the error text
*/
*/
protected
function
getError
(
$htmlOptions
=
array
()
)
protected
function
getError
()
{
{
if
(
isset
(
$this
->
htmlOptions
[
'errorOptions'
]))
{
$htmlOptions
=
$this
->
htmlOptions
[
'errorOptions'
];
unset
(
$this
->
htmlOptions
[
'errorOptions'
]);
}
else
$htmlOptions
=
array
();
return
$this
->
form
->
error
(
$this
->
model
,
$this
->
attribute
,
$htmlOptions
);
return
$this
->
form
->
error
(
$this
->
model
,
$this
->
attribute
,
$htmlOptions
);
}
}
...
@@ -257,9 +264,23 @@ abstract class BootInput extends CInputWidget
...
@@ -257,9 +264,23 @@ abstract class BootInput extends CInputWidget
{
{
if
(
isset
(
$this
->
htmlOptions
[
'hint'
]))
if
(
isset
(
$this
->
htmlOptions
[
'hint'
]))
{
{
if
(
isset
(
$this
->
htmlOptions
[
'hintOptions'
]))
{
$htmlOptions
=
$this
->
htmlOptions
[
'hintOptions'
];
unset
(
$this
->
htmlOptions
[
'hintOptions'
]);
}
else
$htmlOptions
=
array
();
if
(
isset
(
$htmlOptions
[
'class'
]))
$htmlOptions
[
'class'
]
.=
' help-block'
;
else
$htmlOptions
[
'class'
]
=
'help-block'
;
$hint
=
$this
->
htmlOptions
[
'hint'
];
$hint
=
$this
->
htmlOptions
[
'hint'
];
unset
(
$this
->
htmlOptions
[
'hint'
]);
unset
(
$this
->
htmlOptions
[
'hint'
]);
return
'<p class="help-block">'
.
$hint
.
'</p>'
;
return
CHtml
::
tag
(
'p'
,
$htmlOptions
,
$hint
);
}
}
else
else
return
''
;
return
''
;
...
@@ -267,7 +288,7 @@ abstract class BootInput extends CInputWidget
...
@@ -267,7 +288,7 @@ abstract class BootInput extends CInputWidget
/**
/**
* Returns the container CSS class for the input.
* Returns the container CSS class for the input.
* @return string the CSS class
.
* @return string the CSS class
*/
*/
protected
function
getContainerCssClass
()
protected
function
getContainerCssClass
()
{
{
...
@@ -276,6 +297,48 @@ abstract class BootInput extends CInputWidget
...
@@ -276,6 +297,48 @@ abstract class BootInput extends CInputWidget
}
}
/**
/**
* Returns the input container CSS classes.
* @return string the CSS class
*/
protected
function
getInputContainerCssClass
()
{
$classes
=
array
();
if
(
isset
(
$this
->
htmlOptions
[
'prepend'
]))
$classes
[]
=
'input-prepend'
;
if
(
isset
(
$this
->
htmlOptions
[
'append'
]))
$classes
[]
=
'input-append'
;
return
implode
(
' '
,
$classes
);
}
/**
* Returns the HTML attributes for the CAPTCHA widget.
* @return array the attributes
* @since 0.10.0
*/
protected
function
getCaptchaOptions
()
{
if
(
isset
(
$this
->
htmlOptions
[
'captchaOptions'
]))
{
$htmlOptions
=
$this
->
htmlOptions
[
'captchaOptions'
];
unset
(
$this
->
htmlOptions
[
'captchaOptions'
]);
}
else
$htmlOptions
=
array
();
return
$htmlOptions
;
}
/**
* Returns whether the input has an add-on (prepend and/or append).
* @return boolean the result
*/
protected
function
hasAddOn
()
{
return
isset
(
$this
->
htmlOptions
[
'prepend'
])
||
isset
(
$this
->
htmlOptions
[
'append'
]);
}
/**
* Renders a checkbox.
* Renders a checkbox.
* @return string the rendered content
* @return string the rendered content
* @abstract
* @abstract
...
...
widgets/input/BootInputHorizontal.php
View file @
bc8704c3
...
@@ -32,16 +32,15 @@ class BootInputHorizontal extends BootInput
...
@@ -32,16 +32,15 @@ class BootInputHorizontal extends BootInput
*/
*/
protected
function
getLabel
(
$htmlOptions
=
array
())
protected
function
getLabel
(
$htmlOptions
=
array
())
{
{
$classes
=
'control-label'
;
if
(
!
isset
(
$this
->
htmlOptions
[
'labelOptions'
]))
if
(
isset
(
$htmlOptions
[
'class'
]))
$this
->
htmlOptions
[
'labelOptions'
]
=
array
();
$htmlOptions
[
'class'
]
.=
' '
.
$classes
;
if
(
isset
(
$this
->
htmlOptions
[
'labelOptions'
][
'class'
]))
$this
->
htmlOptions
[
'labelOptions'
][
'class'
]
.=
' control-label'
;
else
else
$htmlOptions
[
'class'
]
=
$classes
;
$this
->
htmlOptions
[
'labelOptions'
][
'class'
]
=
'control-label'
;
if
(
isset
(
$this
->
htmlOptions
[
'id'
]))
$htmlOptions
[
'for'
]
=
$this
->
htmlOptions
[
'id'
];
return
parent
::
getLabel
(
$htmlOptions
);
return
parent
::
getLabel
();
}
}
/**
/**
...
@@ -197,7 +196,7 @@ class BootInputHorizontal extends BootInput
...
@@ -197,7 +196,7 @@ class BootInputHorizontal extends BootInput
{
{
echo
$this
->
getLabel
();
echo
$this
->
getLabel
();
echo
'<div class="controls"><div class="captcha">'
;
echo
'<div class="controls"><div class="captcha">'
;
echo
'<div class="widget">'
.
$this
->
widget
(
'CCaptcha'
,
$this
->
data
,
true
)
.
'</div>'
;
echo
'<div class="widget">'
.
$this
->
widget
(
'CCaptcha'
,
$this
->
getCaptchaOptions
()
,
true
)
.
'</div>'
;
echo
$this
->
form
->
textField
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
form
->
textField
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div></div>'
;
echo
'</div></div>'
;
...
...
widgets/input/BootInputVertical.php
View file @
bc8704c3
...
@@ -16,19 +16,6 @@ Yii::import('bootstrap.widgets.input.BootInput');
...
@@ -16,19 +16,6 @@ Yii::import('bootstrap.widgets.input.BootInput');
class
BootInputVertical
extends
BootInput
class
BootInputVertical
extends
BootInput
{
{
/**
/**
* Renders a CAPTCHA.
* @return string the rendered content
*/
protected
function
captcha
()
{
echo
$this
->
getLabel
()
.
'<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
();
echo
'</div>'
;
}
/**
* Renders a checkbox.
* Renders a checkbox.
* @return string the rendered content
* @return string the rendered content
*/
*/
...
@@ -158,6 +145,19 @@ class BootInputVertical extends BootInput
...
@@ -158,6 +145,19 @@ class BootInputVertical extends BootInput
}
}
/**
/**
* Renders a CAPTCHA.
* @return string the rendered content
*/
protected
function
captcha
()
{
echo
$this
->
getLabel
()
.
'<div class="captcha">'
;
echo
'<div class="widget">'
.
$this
->
widget
(
'CCaptcha'
,
$this
->
getCaptchaOptions
(),
true
)
.
'</div>'
;
echo
$this
->
form
->
textField
(
$this
->
model
,
$this
->
attribute
,
$this
->
htmlOptions
);
echo
$this
->
getError
()
.
$this
->
getHint
();
echo
'</div>'
;
}
/**
* Renders an uneditable field.
* Renders an uneditable field.
* @return string the rendered content
* @return string the rendered content
*/
*/
...
...
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