Sequence of events from a submit button - submit

I have a simple test page that I'm trying work through the sequence of events and how to handle a querySaveDocument failure.
As far as I can see the sequence of events is
onclick of submit
validation
querySaveDocument
save document
in the submit action I return 'success' but that happens regardless of whether the querySave returns true or false. Now what I want to do is if the querySave fails return tio the same document the same way as the validation does. So I believe that setting the return 'success' in the onclick event is what is causing the problem but how do I trap the querySaveDocument and if it fails just return otherwise do the 'success' navigation.
This should not be that difficult but I think it is because the querySaveDocument is a backend event. But I would think that this sort of process would be something that people would do pretty regularly. I want to do the querySave after the validation because there is no point in attempting to do a rather involved querySaveDocument event only if the document is ready to be saved.
I thought of doing the submit button return in an onComplete event but that does not appear to work. ??
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.navigationRules>
<xp:navigationRule outcome="success" viewId="xpMain.xsp">
</xp:navigationRule>
</xp:this.navigationRules>
<xp:button value="Submit" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" immediate="false" save="true">
<xp:this.action><![CDATA[#{javascript:println("In Submit")
return 'success';}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
Required FieldĀ 
<xp:inputText id="inputText1" value="#{document1.BusinessUnit}">
<xp:this.validators>
<xp:validateRequired message="Please enter a value"></xp:validateRequired>
</xp:this.validators>
<xp:this.required><![CDATA[#{javascript:println("In Validation");
return "This is a requiedd Field";}]]>
</xp:this.required>
</xp:inputText>
<xp:this.data>
<xp:dominoDocument databaseName="Client Apps\LGI\LGI Rules.nsf"
formName="frmCLRule" var="document1">
<xp:this.querySaveDocument>
<![CDATA[#{javascript:println("In QuerySave");
return false;}]]>
</xp:this.querySaveDocument>
</xp:dominoDocument>
</xp:this.data>
<xp:br></xp:br>
<xp:br></xp:br>
</xp:view>

when i run the code, I see the order of execution is submit event, querySaveDocument and then navigation rule.
Use a viewScope variable in querySaveDocument event to record success or failure and then use that in navigationRule. Sample code below.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.navigationRules>
<xp:navigationRule viewId="xpMain.xsp">
<xp:this.outcome><![CDATA[#{javascript:if ( viewScope.qrySave ) {
return 'success';
}}]]></xp:this.outcome>
</xp:navigationRule>
</xp:this.navigationRules>
<xp:button value="Submit" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" immediate="false" save="true">
<xp:this.action><![CDATA[#{javascript:println("In Submit")
return 'success';}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
Required FieldĀ 
<xp:inputText id="inputText1" value="#{document1.BusinessUnit}">
<xp:this.validators>
<xp:validateRequired message="Please enter a value"></xp:validateRequired>
</xp:this.validators>
<xp:this.required><![CDATA[#{javascript:println("In Validation");
return "This is a requiedd Field";}]]>
</xp:this.required>
</xp:inputText>
<xp:this.data>
<xp:dominoDocument databaseName="Client Apps\LGI\LGI Rules.nsf"
formName="frmCLRule" var="document1">
<xp:this.querySaveDocument>
<![CDATA[#{javascript:println("In QuerySave");
viewScope.qrySave = false;
//viewScope.qrySave = true;
return false;}]]>
</xp:this.querySaveDocument>
</xp:dominoDocument>
</xp:this.data>
<xp:br></xp:br>
<xp:br></xp:br>
</xp:view>

Related

Retrieving input form data Trello power-up

I have created a custom power up that requires settings. I use the show-settings capability for this.
The settings form is shown successfully:
But I don't know how to retrieve data from that form. Getting and setting is for saving en retrieving data, as I understand, but not for getting http params.
I've tried to get parameters like:
function get(parameterName) {
var result = null,
tmp = [];
location.search
.substr(1)
.split("&")
.forEach(function(item) {
tmp = item.split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
return result;
}
Then calling get('webhookUrl') in different places;
outside of window.TrelloPowerUp.initialize({});
inside 'show-settings': function(t, options) {
inside callback in t.popup(..)
Anything I log there, it doesn't seem to work.
app.js:
...
'show-settings': function(t, options) {
// when a user clicks the gear icon by your Power-Up in the Power-Ups menu
// what should Trello show. We highly recommend the popup in this case as
// it is the least disruptive, and fits in well with the rest of Trello's UX
return t.popup({
title: 'Custom Fields Settings',
url: 'settings.html?v=' + timeStamp,
height: 184, // we can always resize later
callback: function(t) {
console.log(t);
}
});
},
In the settings.html
<body>
<form id="settings">
<input name="webhookUrl" placeholder="https://app.buddy.works/user-name/projects-name/pipelines/pipeline .."></input>
<button type="submit" class="mod-primary">Save</button>
</form>
</body>
Btw, i find it hard to debug things in the browser, in Chrome Developers Tools I check Javascript Context, every time I scroll to the right iframe, it is tedious.

Microsoft XmlLite fails to detect end-of-element

I'm using Microsoft's XmlLite DLL to parse a simple XML file, using the code in the example XmlLiteReader. The essential part of the code (C++) is
while(S_OK == (hr = pReader->Read(&nodeType)))
{
switch(nodeType)
{
case XmlNodeType_Element:
// Get name...
WriteAttributes(pReader, es, attributes);
break;
case XmlNodeType_EndElement:
// Process end-of-element...
break;
}
and
HRESULT WriteAttributes(IXmlReader* pReader, CString& es, StringStringMap& attributes)
{
while(TRUE)
{
// Get and store an attribute...
HRESULT hrMove = pReader->MoveToNextAttribute();
}
// ...
}
So, here's my question. With XML input such as
<?xml version="1.0" encoding="utf-8"?>
<settings version="1.2">
<runID name="test" mode="N" take_data="Y">
<cell id="01">
<channel id="A" sample="something"/>
<channel id="B" sample="something else"/>
</cell>
<cell id="03">
<channel id="A" sample="other something"/>
<channel id="B" sample="other something else"/>
</cell>
</runID>
</settings>
Everything works as expected, except that the /> at the end of each channel line, which indicates the end of the element channel, isn't recognized as the end of an element. The successive node types following channel are whitespace (\n), then element (the second channel).
How can I determine from XmlLite that element `channel' has ended? Or am I misunderstanding the XML syntax?
You can test if an element ends with /> by using the function IsElementEmpty.

return back the value of g:textfield

how can i show back the g:textfield value if the value already havebeen taken.
example :
<input type="text" name="simbol" id="simbol" value="${simbol}"/>
when input the textfield with "1A" then SAVE to database, then i input again with type "1A" again. it will be error because i protect with unique : true, when eror it will be return the input page..
and filled by "1A"
how can i do to get the "1A" when save error and return to the page?
catch(Exception E)
{
[simbol: params.simbol?: "",nama : params.nama?:""]
flash.message = "Simbol Sudah Dipakai !!! "
redirect (action:"tambah")
}
i use try cacth to throw unique save error.
and
[simbol: params.simbol?: "",nama : params.nama?:""], this line i tried to throw/get back the value when save eror or unique
You need put back data into model and `render page.
In your code you redirect without params at all.
This is the common way to do that you need. (Controller code)
def unInstance = new Un(params)
if (!unInstance.save(flush: true)) {
render(view: "create", model: [unInstance: unInstance])
return
}
....
}

Can I suppress MVC Client validation from running while programmatically changing input values?

I have a form where the input boxes are prefilled with default values. A jQuery event handler clears the value on 'focus' and restores the default value on 'blur', if the field is empty.
$('form input').on('focus blur', function (event) {
var eventTarget = $(this);
if (eventTarget.val() === eventTarget.data('default')
|| eventTarget.val() === '') {
if (event.type === 'focus') {
eventTarget.val('').removeClass('empty');
} else {
eventTarget.val(eventTarget.data('default')).addClass('empty');
}
}
}).trigger('blur');
Before submitting (via AJAX), I empty all fields that contain the default value and trigger client side validation (for required fields):
$('form').on('submit', function (e) {
$('form input').each(function () {
if ($(this).val() === $(this).data('default')) {
$(this).val(''); // remove default value, so 'required' validation triggers on empty fields
}
});
if ($('form').valid()) {
$.ajax(...);
} else {
$('form input').trigger('blur'); // trigger 'blur' to restore default values
// Problem: This clears the validation messages
}
});
So far, so good, however after that, my form fields are of course empty. If I trigger the 'blur' event again, I can restore the default values, but that makes the validation messages disappear, probably because client side validation runs again and sees that the fields are no longer empty.
When I manually click in and out of the form field, though, the default value is restored and the validation message stays. Both go through the same 'blur' handler. I cannot figure out where the difference is.
Edit:
I have since figured out that I can disable validation on 'blur' completely:
$('form').validate().settings.onfocusout = false;
This works around my issue for now, but I would still like to know why blur/focusout reacts differently when triggered from a script or from user interaction.

struts2 jqgrid: onEditInlineErrorTopics not being called on error

On save of the jqgrid, the action catches a constraint violation exception and returns "error". However, the onEditInlineErrorTopics function is not called on the jsp. The exception needs to be translated to a user message saying "Duplicate Records"
The code is as follows:
JSP grid Code
<sjg:grid id="gridtable"
dataType="json"
href="%{remoteurl}"
loadonce="true"
pager="true"
navigator="true"
scroll="true"
navigatorAdd="false"
navigatorEdit="false"
navigatorView="false"
navigatorDelete="true"
navigatorDeleteOptions="{height:220,reloadAfterSubmit:true,url:'%{deleteurl}'}"
gridModel="gridModel"
rowList="10,15,20"
rowNum="15"
navigatorRefresh="false"
navigatorSearch="false"
editurl="%{editurl}"
editinline="true"
navigatorInlineEditButtons="true"
gridview="true"
viewrecords="false"
shrinkToFit="true"
onEditInlineErrorTopics="onediterror">
Tried these tags as well
errorElementId, errorText & onErrorTopics
Action header (annotations)
#ParentPackage(value = "basicstruts2")
#Action(value = "/editDetails",
results = {
#Result(name="success",type="json"),
#Result(name="error",type="json"),
#Result(name="none",type="json"),
#Result(name="input",type="json")
})
Action catch block
catch(Exception e){
addActionError("Duplicate Records. Please enter again.");
return "error";
}
The Json string created is:
{"JSON":"error","field1":"1","field2":3,"oper":"edit","field3":5,"field4":"9","field5":null,"field6":null,"field7":"19","field8":156}
Tried throwing exception in the catch block but it shows the stacktrace in a popup.
Tried the success topic onEditInlineSuccessTopics as mentioned in the showcase here and it works fine.

Resources