I want to display a Zend Form with one of the elements shown as disabled. I'm setting the value so the user can see it, but I want to disable it so the user can't edit it. This may also involve some sort of css/javascript to ensure that it looks like, and is not editable by the user. This is my element:
$this->addElement('text', 'username', array(
'label' => 'Username:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(2, 50))
)
));
You should be able to use:
$this->username->setAttrib('disabled', 'disabled');
I think you can as well:
$this->addElement('text', 'username', array(
'label' => 'Username:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(2, 50))
),
'attribs' => array('disabled' => 'disabled')
));
This works fine...
Just to complete the help:
If you are in a controller you can do:
$form->selRole->setAttribs(array('disable' => 'disable'));
selRole is the name of a select field
In latest zf2.2.1 you can do this in your controller;
$form->get('username')->setAttributes(array(
'disabled' => 'disabled',
));
$form->getElement("username")->setAttribs(array('disabled' => 'disabled', ));
or
$form->getElement("username")->setAttrib('disabled', 'disabled');
$var->setAttribs(array('disabled' => 'disabled'));
Apply this code into your Application
$formelement->setAttrib('readonly', 'true');
$formelement->setAttrib('style', 'pointer-events: none');
Only this was working for me, when using a file element when setting after form was submitted:
$element->setValueDisabled(true);
// disable checkbox using JS add-on
$checkbox->setAttribute('onclick', 'return false');
Benefit: retains the original color of the box but does not let the user change the value of the box.
Using disabled method of other answers changes the color of checkbox to "grayed out". Method described here, does not.
#Dennis:
Disabling Javascript is enough to enable the form again, so you can't truly rely on Javascript. Using native HTML disables it better, but is also simply worked around, by removing the disabled attribute.
Best option is showing the values you want instead of the form itself and disable the form and/or it's elements.
Wish I could add the comment directly to your post, but I'm some rep short.
Related
I want to add a custom drop down in tiny mce editor, I am using yii framework and using a yii plugin to integrate the editor
You haven't added any details in your question but since you are a new
bee here and SO Code of Conduct
has been revised to be more nice and humble towards newcomers, so I am
adding the answer for you, do go through the How to Ask a
Question? before posting a
question next time.
You can add the dropdown in the TinyMCE using setup option which takes a callback function with a parameter editor which holds the editor instance, and then you need to call the editor.addButton(label, options) with the options to create the custom dropdown button.
As you have not added any details in the question like what are the options that you are going to display in the dropdown so, I will assume here as usernames from the database in the variable $users.
Steps to Implement
First, we will convert $users array to js array by using yii\helpers\Json::encode().
Iterate that array to create the drop-down options with onclick event to insert the content to the editor.
Use editor.addButton('users',options) to create a button of type dropdown with label users to be later used when initializing the editor toolbar buttons.
Add the following code on top of the view
$usersList = \yii\helpers\Json::encode($users);
$tinyMCECallback = <<< JS
function (editor) {
let usersList = $usersList;
let options = [];
//iterate the user array and create the options with text and
//onclick event to insert the content on click to the editor
$.each(usersList, function(label, mapping) {
options.push({
text: label,
onclick: function() { tinymce.activeEditor.insertContent(label); }
});
});
//add the dropdown button to the editor
editor.addButton('users', {
type: 'menubutton',
text: 'Users',
icon: false,
menu: options
});
}
JS;
Now all you need to do is to pass the $tinyMCECallback to the setup option of the tinyMCE widget, if you are using the active form you code should be like below.
Note: Don't forget to add the users label of the button to the toolbar options, or if you change it in the javascript code change it accordingly in the editor toolbar options otherwise it won't show up
<?php
echo $form->field(
$model, 'body'
)->widget(
TinyMce::class, [
'options' => ['rows' => 10],
'language' => 'en',
'clientOptions' => [
'menubar' => false,
'statusbar' => false,
'toolbar' => "undo redo | users",
'setup' => new \yii\web\JsExpression($tinyMCECallback),
],
]
);
?>
I have selecting, unselect and unselecting event. But when I click on select all or unselect all none of these events are called.
This is the plugin link
http://demos.krajee.com/widget-details/select2
There is an event that is fired. Its logic is defined in here:
Select2 Krajee JS Official Source Code
The name of the event for select all is krajeeselect2:selectall and for unselect all is krajeeselect2:unselectall.
Consuming the event via JQuery is done as always:
$('#myKartikSelect2Id').on("krajeeselect2:selectall", function (e) {
console.log(e);
});
$('#myKartikSelect2Id').on("krajeeselect2:unselectall", function (e) {
console.log(e);
});
Hope it helps (:
I don't find better solution but with this options you can override "Select all" checkbox with empty space.
'toggleAllSettings' => [
'selectLabel' => '',
'unselectLabel' => '',
'selectOptions' => ['class' => 'text-success'],
'unselectOptions' => ['class' => 'text-danger'],
],
Maybe not very correct, but using this works $this->renderAjax()
Mainly I have to hide the debugger on every view pages in cakephp3. Can anybody give me any suggestions regarding this ?
Go to config/bootstrap.php file and find following somewhere:
Plugin::load('DebugKit', ['bootstrap' => true]);
Change it to:
Plugin::load('DebugKit', ['bootstrap' => false]);
Go to Config/app.php file and change
'debug' => filter_var(env('DEBUG', 1), FILTER_VALIDATE_BOOLEAN)
with this
'debug' => filter_var(env('DEBUG', 0), FILTER_VALIDATE_BOOLEAN)
I'm using CMB2 to allow for front end submissions using a custom post type. The code works well but the problem is that it doesn't support menu bar. There's the textarea, submit button and the title but menu bar is not showing. What could be the problem?
Below is my code:
$cmb->add_field( array(
'name' => __( 'New Post Content', 'wds-post-submit' ),
'id' => 'submitted_post_content',
'type' => 'wysiwyg',
'options' => array(
'wpautop' => true, // use wpautop?
'media_buttons' => true, // show insert/upload button(s)
'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
'tabindex' => true,
'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the `<style>` tags, can use "scoped".
'editor_class' => '', // add extra class(es) to the editor textarea
'teeny' => false, // output the minimal editor config used in Press This
'dfw' => false, // replace the default fullscreen with DFW (needs specific css)
'tinymce' => array(
'menubar' => true;
), // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
),
) );
A little late, but: change
'menubar' => true;
to
'menubar' => true,
I am using elgg 2.0(alpha). Now i want to remove powered by text (in footer) and write my site name.
Default text is Powered by Elgg and link to http://elgg.org.
How can i change/remove this?
You can use the elgg basic function for that.
First register the method in init.
function theme_init() {
elgg_register_event_handler('pagesetup', 'system', 'theme_pagesetup', 1000);
}
And then
function theme_pagesetup() {
elgg_register_menu_item('footer', ElggMenuItem::factory(array(
'name' => 'powered',
'text' => 'My site', `keep empty if you dont want`
'href' => 'http://website.com',
'section' => 'meta',
'priority' => 1,
)));
}
Using this you can easily remove/change footer text.