XPages Repeat control, compute visible - repeater

I have global context document currentDoc and repeat control with responses of currentDoc.
In repeat control i have 2 fields:
1) ComboBox
2) Editbox, with computed Visible by ComboBox:
var temp = respDoc.getItemValueString( "Combobox1");
return temp == "a";
Onchange event ComboBox i update repeat control.
And i have button "Add response" (create/save response and update repeat control)
Its work. But.. if i create response and save this, field with computed Visible reset to "" and not saved. If i re-enter text to Editbox and re-saved, then Ok. Only works after re-saving. Have not errors.
May be you know, what problem?
Source code
<xp:this.data>
<xp:dominoDocument var="curDoc" formName="test"></xp:dominoDocument>
</xp:this.data>
<xp:repeat id="repeat1" rows="30" var="respDoc"
repeatControls="false"
indexVar="respDocIndex" value="#{javascript:return curDoc.getDocument().getResponses();}">
<xp:panel id="panel1">
<xp:table>
<xp:tr>
<xp:td style="width:150.0px">
<xp:comboBox id="comboBox1" style="width:95%"
value="#{respDoc.combobox}" required="false">
<xp:selectItem
itemLabel="Email" itemValue="a">
</xp:selectItem>
<xp:selectItem itemLabel="UserName"
itemValue="b">
</xp:selectItem>
<xp:eventHandler event="onchange"
submit="true" refreshMode="partial" refreshId="repeat1">
</xp:eventHandler>
</xp:comboBox>
</xp:td>
<xp:td>
<xp:inputText id="inputText2"
value="#{respDoc.editbox}" maxlength="20">
<xp:this.rendered><![CDATA[#{javascript://return true <---- if uncomment it, then all work
var temp = respDoc.getItemValueString( "combobox");
return temp == "b";}]]></xp:this.rendered>
</xp:inputText></xp:td>
<xp:td>
<xp:button value="Save" id="button4">
<xp:eventHandler event="onclick"
submit="true" refreshMode="partial" refreshId="repeat1">
<xp:this.action><![CDATA[#{javascript:respDoc.save();}]]></xp:this.action>
</xp:eventHandler></xp:button>
</xp:td>
</xp:tr>
</xp:table>
</xp:panel>
</xp:repeat>
<xp:button value="Add Response" id="button2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="repeat1">
<xp:this.action><![CDATA[#{javascript:if(curDoc.isNewNote())
curDoc.save();
var doc:NotesDocument = database.createDocument();
doc.replaceItemValue("Form", "test");
doc.makeResponse(curDoc.getDocument());
doc.save();}]]></xp:this.action>
</xp:eventHandler>
</xp:button>

Your approach has a number of issue:
A server roundtrip is initiated on the change of a checkbox, which is an unexpected behavior for a form
A document that has not been saved can't have responses, so you shouldn't show the repeat
When you create a new document you don't assign the "combobox" item any value,so your test temp =="b" fails.
When no rendered, no value is send back to the server, that might not be what you want
I would use style="display : none" to hide the field on the client side and have the event only run on the client. also add a value to your combobox when creating a new document:
var doc:NotesDocument = database.createDocument();
doc.replaceItemValue("Form", "test");
doc.makeResponse(curDoc.getDocument());
doc.replaceItemValue("Combobox1","a");
doc.save();
doc.recyle();
Hope that helps

Related

In Semantic-UI-React, is there a way to add an x icon to a text input or dropdown that will clear the text when clicked?

I have both a text input and a dropdown that allows additions (both use the Form.xxx version). For both of these, I would like to add an x icon on the right, that when clicked, will either call a handler or will clear the input's value.
Is this possible in semantic-ui-react?
Thank you
I did find a solution, which I will share, but this means I can no longer have my lock icon on the left hand side, because an input can only have one icon.
What I've done is to use an Icon element, and add an onClick handler to that, as follows:
<Input ...
icon={<Icon name='delete' link onClick={this.handleDeleteClick}/>}/>
(Updated)
To clear the field, there is no "semantic-ui-react" shortcut as far as I know.
However, you can do this manually using your component state.
Here would be an example of this:
class ExampleClearField extends Component {
state = {}
handleChange = (e, { name, value }) => this.setState({ [name]: value })
handleClear = () => this.setState({ email: ''})
render() {
const { email } = this.state
return (
<Form.Input iconPosition='left' name="email />
<Icon name='x' link onClick={this.handleClear} />
<input/>
</Form.Input>
)
}
}
** Notice the link, which is needed for Icon to accept onClick.
Also, dont't forget about (you might need to change it's place depending on iconPostion)
As of Semantic UI React 0.83.0, it is possible to do this with Dropdowns using clearable. You cannot add your own event handler to the "x" by using this. Clicking the "x" will simply clear the selected value and call onChange with the new empty value.
Example from their docs:
const DropdownExampleClearable = () => <Dropdown clearable options={options} selection />
See the example output on their docs page here

Flex Change List Item Selected While Mouse Down

I am trying to create a List which behaves like, for example, the Finder Menu on my Mac. In other words if I click on a List Item, keep my mouse down and move up and down the List I want the Selected Item to change.
In my Flex application if I click on my List and then, with the mouse still down, move up and down the List the Selected Item remains the same.
Any advice would be gratefully received.
Thanks
In StackOverflow tradition I am posting a solution to my own problem after working at it more:
I had an ItemRenderer on my List. In the ItemRenderer I declared a variable to hold a reference to the owning List.
private var _parentList:List;
In the 'set data' function I set this variable to the owner List.
override public function set data(value:Object):void {
super.data = value;
// Check to see if the data property is null.
if (value == null)
return;
// If the data property is not null.
// Get a reference to the parent list.
_parentList = this.owner as List;
...
I then added an EventListener to listen for MouseDown events.
// Attach an eventListener to the ItemRenderer.
this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
...
My onMouseOver handler looks like this.
private function onMouseOver(event:MouseEvent):void {
//trace(data.LocationName);
if (event.buttonDown == true) {
_parentList.selectedIndex = itemIndex;
}
}
So with this in place I can mouse-down on my List and keeping the mouse button depressed move up and down the List with the List Item beneath the cursor always being selected. The final piece to this is to ensure that the List responds to the selectedIndex being set by the ItemRenderer. When the user changes the selectedIndex property by interacting with the control, the control dispatches the change and changing events. When you change the value of the selectedIndex property programmatically, it dispatches the valueCommit event. To ensure I responded to my programmatic changing of the selected list item I added a handler to the valueCommit event.
<s:List
id="locationsList"
dataProvider="{presenter.locations}"
itemRenderer="itemrenderers.locationListItemRenderer"
useVirtualLayout="false"
width="1869.698" height="1869.698"
y="65.151" x="65.151"
borderVisible="true"
borderColor="{presenter.backgroundColour}"
contentBackgroundAlpha="0"
contentBackgroundColor="0xff336c"
labelField="label"
change="presenter.onLocationListChange(event)"
valueCommit="presenter.onLocationListValueCommit(event)">
<s:layout>
<s:BasicLayout />
</s:layout>
</s:List>
So far it seems to work fine. Hope it helps.

Flex mobile prevent item renderer state from recycled

I have this custom list item renderer where I have defined 2 custom states:
<s:states>
<s:State name="expand"/>
<s:State name="collapse"/>
</s:states>
When I select one of the list item, it will change to state collapse. Now whenever I select the first or the last item in the list and I refresh the data provider, the current state of both the items will swap places.
Please guide me on how to retain the state of the itemrenderer. Thank you.
Note: It all works well when I change the usevirtuallayout to false. But, it is not what I intended to change.
[Edit]
The following is my code for the item renderer:
<fx:Script>
<![CDATA[
protected function init(event):void
{
currentState = "collapse";
}
override public function set data(value:Object):void
{
trace(currentState.toString());
}
protected function btn_clickHandler(event:MouseEvent):void
{
currentState = "expand";
}
]]>
</fx:Script>
<s:states>
<s:State name="expand"/>
<s:State name="collapse"/>
</s:states>
<s:Button id="changeStateButton" click="btn_clickHandler(event)"/>
The example above is a simple item renderer where a single button will change the currentState of the itemrenderer. I have 3 items in the data provider and each one of them is in the "collapse" state by default. This is the trace result from the set data function:
collapse
collapse
collapse
When I click the button at the last item... this will be the trace result:
collapse
collapse
expand
Now, when I refresh the data provider by calling this function "arraycollection.refresh()"...this is the result:
expand
collapse
collapse
Can somebody explain this scenario? Notice that this only happens when the useVirtualLayout is set to true...
Try reassigning the item renderer after updating the data provider.
//update data provider
itemList.dataProvider = myCollection;
//update the item renderer
itemList.itemRenderer = new ClassFactory(cutomItemRenderer);
This solution of course will be more resource intensive.

Silverlight ComboBox Returns Null on second run

I have a 3 cascading combo boxes: cb1, cb2, cb3.
cb3 values depend on cb2 and cb2 values depend on cb1 value.
These comboboxes are located inside a DataForm.EditTemplate
The first time I edit an item, everything get's populated.
The second time I edit another item,
cb1, gets populated while
cb2 & cb3 values disappear.
When I debug my code,
this is the codebehind snippet.
var cboC2 = (ComboBox)ProductRequestForm.FindNameInContent("cb2");
var cboC3 = (ComboBox)ProductRequestForm.FindNameInContent("cb3");
returns null.
But when I run again
no error occurs.
Heres my xaml code.
<dataform:DataField LabelPosition="Top" Label="Status" IsRequired="True" Grid.Row="2" Grid.Column="1">
<ComboBox x:Name="cb2"
SelectedItem="{Binding ProductRequestStatus, Mode=TwoWay}"
DisplayMemberPath="ProductRequestStatusDescription" SelectionChanged="cb2_SelectionChanged" />
</dataform:DataField>
<dataform:DataField LabelPosition="Top" Label="Severity" IsRequired="True" Grid.Row="4" Grid.Column="1">
<ComboBox x:Name="cb3"
SelectedItem="{Binding ProductRequestSeverity, Mode=TwoWay}"
DisplayMemberPath="ProductRequestSeverityDescription" />
</dataform:DataField>
These are triggered by an event SelectionChanged.
Please help.
Thank you.

Pass values to content page from programmatically added masterpage menuitem?

I'm working on a project that uses a master page and content pages. My masterpage a navigation bar:
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/ProjectPage.aspx" Text="Home" />
<asp:MenuItem NavigateUrl="~/ProductBacklog.aspx" Text="Product Backlog"/>
<asp:MenuItem NavigateUrl="~/SprintBacklog.aspx" Text="Sprint Backlog" />
<asp:MenuItem NavigateUrl="~/MeetingPage.aspx" Text="Meetings" />
<asp:MenuItem NavigateUrl="~/Burndown.aspx" Text="Burndown"/>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="About Us"/>
</Items>
</asp:Menu>
On one of my content pages, I dynamically add sub-menu menuitems to my 'Sprint Backlog' menuitem. There is a button, and everytime the user clicks that button, a sub-menuitem is added, so that when the user hovers over 'Sprint Backlog' in the navigation menu, the submenu comes up. I do this by creating a list of menuitems, creating a new menuitem with (shown text, value, navigationURL), adding the menuitem to the list of menuitems, then saving the list to Session:
protected void btSave_Click(object sender, EventArgs e)
{
menuItemList = (List<MenuItem>)Session["menuItemList"];
if (menuItemList == null)
{
menuItemList = new List<MenuItem>();
}
MenuItem menuItem = new MenuItem("Sprint " + sprintNumber, sprintNumber.ToString(), "SprintBacklog.aspx");
menuItemList.Add(menuItem);
Session["menuItemList"] = menuItemList;
}
In the code-behind for my masterpage, I create a list of menuitems, set the value of the instance of the menuitem from Session, and add childitems to the navigationmenu at the appropriate index. The childitem I am adding are the menuitems from the list of menuitems.
List<MenuItem> menuItemList;
protected void Page_Load(object sender, EventArgs e)
{
menuItemList = (List<MenuItem>)Session["menuItemList"];
if (menuItemList != null)
{
foreach (MenuItem menuitem in menuItemList)
{
NavigationMenu.Items[2].ChildItems.Add(menuitem);
}
}
}
I know that I gave these childitems a value when I created them, but my problem is accessing those values when I am loading the SprintBacklog.aspx content page. Whenever a user clicks on one of the childitems, it will always navigate to SprintBacklog.aspx, but the contents of that page should differ according to which child item they clicked. I need a way to know which childitem they clicked, and access that value to populate my content page.
If someone has a better way for me to carry this whole thing out, I am open for suggestions and change. Otherwise, if my setup can work, and there is a way for me to extract the value of the clicked childitem, I'd really like to know that.
I know if I hard-code the childitems in my masterpage, I can easily get the value, but my problem is that I'm creating the submenu childitems dynamically, and I'm not sure how to access it.
Any help would be really appreciated! Thanks!
-Jose
It's been a long time since I asked this question, and I'm not familiar with how masterpages work anymore, but if anyone is experiencing anything similar, I may have a suggestion.
Each menu item I was creating was linking to SprintBacklog.aspx like so:
MenuItem menuItem = new MenuItem("Sprint " + sprintNumber, sprintNumber.ToString(), "SprintBacklog.aspx");
What I should have done was link to SprintBacklog.aspx, but also add a parameter to the request with the sprint ID.
Then the controller which handles the rendering of SprintBacklog.aspx would read the parameter and fetch the appropriate data to render.