Moodle Create Radio buttons group - moodle

I am new to moodle. This is a very basic question , i have searched a lot but not able to correctly create a group of radiobuttons. I have not created radio buttons so far in moodle forms earlier.
I want two radio buttons,with labels "award" and "deduct", in a local plugin i am creating.
Code i wrote :
$awardingTypeRadioArr = array();
$awardingTypeRadioArr[0] = $mform->createElement( 'radio','award','',get_string('clAwardRadioLbl','local_hps'));
$awardingTypeRadioArr[1] = $mform->createElement( 'radio','award','',get_string('clDeductRadioLbl','local_hps'));
$mform->addGroup( $awardingTypeRadioArr,'awardingType' );
I get the radio buttons and labels, but the second of the two is checked by default. Bigger problem is,I am not getting anything for the radio buttons in the form data.
Please clarify how to do this.
Thanks.

You have to use 'award' instead of 'awardingType' in the below line :
$mform->addGroup( $awardingTypeRadioArr,'awardingType' );
Also to set a detault value you can use
$mform->setDefault() function.
Hope this helps

Related

Radio Buttons - Powershell

I have created a Power Shell form which allows me to input users into a text box and mark whether I want to add/remove them from a particular group. Now, I have grouped all of these into a single group.
How can I still group my radio buttons, but allow for multi select?
For example,
In input box 1, I want to add a user.
In input box 2, I want to remove the user,
In input box 3, I want to add a user.
So I'm not wanting to select Add and Remove for the same input box, just one selection per input box. Hope that makes sense and all help is appreciated!
Put each two radio buttons for a group in a container object like a Panel or a GroupBox. That will automatically group them together.
Krisz's answer is right, you need to group them. When they all sit on the form they are all in one big group and only one can be clicked.
here is a snippit of code I have where I did this as part of a sample, hope it helps:
$MyGroupBox = New-Object System.Windows.Forms.GroupBox
$MyGroupBox.Location = '195,66'
$MyGroupBox.size = '133,122'
$MyGroupBox.text = "Group of radios"
$MyGroupBox.Controls.AddRange(#($GroupRadiobutton1,$GroupRadioButton2,$GroupRadioButton3))
$form.controls.add($MyGroupBox)

Display checkbox inside a listbox

In my (programmatic) Matlab GUI, I have a listbox uicontrol.
What I want is to display checkboxes in front of each option. When a user clicks the checkbox, it's marked (and the element will be considered during the calculations later). While if the user clicks the label, a description of the selected option will be displayed in a text uicontrol to inform the user what the option means.
Basically, I want functionality similar to installation programs where you can select components to install and can get information about said components by clicking them (which does not necessarily mark them as selected).
Is there a way to do this with checkboxes or something similar?
There are actually 2 built-in controls that you could use within Matlab:
com.jidesoft.swing.CheckboxList
com.mathworks.mwswing.checkboxlist.CheckBoxList
Usage example (more details in my Matlab-Java book):
jList = java.util.ArrayList; % any java.util.List will be ok
jList.add(0,'First');
jList.add(1,'Second');
jList.add(2,'Third');
jList.add(3,'and last');
jCBList = com.mathworks.mwswing.checkboxlist.CheckBoxList(jList);
jScrollPane = com.mathworks.mwswing.MJScrollPane(jCBList);
[jhCBList,hContainer] = javacomponent(jScrollPane,[10,10,80,65],gcf);
set(jCBList, 'ValueChangedCallback', #myMatlabCallbackFcn);
jCBModel = jCBList.getCheckModel;
jCBModel.checkAll;
jCBModel.uncheckIndex(1);
jCBModel.uncheckIndex(3);
There's no "ready" way for doing that - as listboxes take only plain strings as entries.
You could "manually" draw checkbox fitted into the area of the listbox, but that might mean quite a lot of work to get everything working...
Another alternative is to go for a java-componenent - e.g. using the jide components available in matlab. See e.g.
http://undocumentedmatlab.com/blog/using-jide-combo-boxes/
for a few examples.

how to hide and unhide authoerable tabs depending upon value selected from a drop down in CQ5

i am trying to create a footer component in CQ5, where i have 4 columns & all are autherable.
But we have to make no of columns autherable too i.e based on a value selected form a dropdown we have to open those many tabs for authoring those many columns only.
i have created a dropdown and have a maximum range of 6 columns. i know that i have to configure a listener for this purpose but don't know how . Requirement is like if i select 3 from the drop down then 3 tabs should come to author 3 columns
pls help me , i am middle of something very important.i need the solution very early too as i have to finish the job as soon as possible
I might be late for this by now but in case you still need it:
You need to add a listener node before closing your drop-down element:
<listeners
jcr:primaryType="nt:unstructured"
loadcontent="function(box){ //here you also need to handle the hide/unhide when the panel loads for the first time. Use this.getValue() to retrive the intial value }"
selectionchanged="function(box, value) {
for(var c=1;c<=value;c++){
this.findParentByType('tabpanel').unhideTabStripItem("tab"+c); // You need to handle the opposite with hideTabStripItem("tab"+c);
}
}"/>
Then on both "loadcontent" and "selectionchange" (these are events on your drop-down) grab the current selected value and use it to hide/unhide the tabs. In this case the tabs would be named "tab1", "tab2", etc, make sure you get the names right.
The ExtJS in the events is finding the "tabpanel" container for the whole dialog, and then hiding/unhiding based on name. You could also set to enable/disable using the methods ".enable()" and ".setDisabled(true)". Just make sure you get the reference to the tab first if you want to do this (something like ".getComponent(tabName).enable()").
I didn't test this specific code, I couldn't find my actual example from my code base but this should take you in the right direction.

GXT 3 spinnerField validation

I want to validate that user cannot change spinner value manually by typing in text box of spinner.
For example a field sales multiple = x which I fetched from server not fix.
and displays a spinner field with limitation of like bellow
spinner.setMinValue = x
spinner.setIncrement = x
spinner.setValue = x
so user forcefully select a value which is multiple with x. e.g. if x=3 the user have to enter 3,6,9... and so on.
So here my issue is if I type a 2 in spinner field text box. GXT widget accept that value.
Posible solutions:
Is there any predefined properties of spinnerfield that i forget to set it?
Is there any predefined validator for this?
Can I set text box of spinner field read only by css so user cannot focus on text box but still change a value.
If none of above how to achieve manually?
i've searched a bit in the different classes and I don't see either a precise method which would set what you want.
Don't know about one, and even with one, a validator doesn't change the value in the input field, but maybe it's enough for your needs.
You can disable the text input by calling setEditable(boolean) on the spinnerfield (testSpinner.setEditable(false);)
Maybe you could search around the IntegerPropertyEditor, I haven't tried but as long as a new Spinner is like this:
SpinnerField<Integer> testSpinner = new SpinnerField<Integer>(new NumberPropertyEditor.IntegerPropertyEditor());
you can seen that there is another Constructor for IntegerPropertyEditor, which takes a "NumberFormat" param, but there is no NumberFormart() constructor, so I'm not sure about how you create your own one, but that could be an idea (to format numbers in the input to be a multiple of the increment).
The last option would be that Sencha forgot this possibility and that you should report this as a "bug" on the forum ?
Hope to have helped a bit, good luck :).

dynamically creating push buttons in matlab

i am trying to create a GUI in matlab, in which dynamically the buttons must be created.
i.e when the user selects the directory, as many number of buttons will be created as many number of files are there in the selected directory. How can one achieve that? any help will be seriously appreciated.
You want to use the handle graphics and more specifically the handle-graphics components. From the same webpage you can see the code to create a button programmatically,
h = figure('ToolBar','none');
ht = uitoolbar(h);
a = rand(16,16,3);
htt = uitoggletool(ht,'CData',a,'TooltipString','Hello');
and also set their callback/handler properties as a property-value pair.