문제

We have a very long form that has a number of fields and 2 different submit buttons. When a user clicks the 1st submit button ("Photo Search") the form should POST and our script will do a search for matching photos based on what the user entered in the text input ("photo_search_text") next to the 1st submit button and reload the entire form with matching photos added to the form. Upon clicking the 2nd submit button ("Save Changes") at the end of the form, it should POST and our script should update the database with the information the user entered in the form.

Unfortunately the layout of the form makes it impossible to separate it into 2 separate forms. I checked the entire form POST and unfortunately the submitted fields are identical to the perl script processing the form submission no matter which submit button is clicked so the perl script can't differentiate which action to perform based on which submit button is pushed. The only thing I can think of is to update the onclick action of the 2nd submit button so it clears the "photo_search_text" field before the form is submitted and then only perform a photo search if that fields has a value.

Based on all this, my question is what does the JavaScript look that could clear out the "photo_search_text" field when someone clicks on the 2nd submit button? Here is what I've tried so far none of which has worked successfully:

<input type="submit" 
       name="submit" 
       onclick="document.update-form.photo_search_text.value='';" 
       value="Save Changes"
>

<input type="submit" 
       name="submit" 
       onsubmit="document.update-form.photo_search_text.value='';" 
       value="Save Changes"
>

<input type="submit" 
       name="submit" 
       onclick="document.getElementById('photo_search_text')='';" 
       value="Save Changes"
>

We also use JQuery on the site so if there is a way to do this with jQuery instead of plain JavaScript feel free to provide example code for that instead. Lastly, if there is another way to handle this that I'm not thinking of any and all suggestions would be welcome.

Thanks in advance for your help!

도움이 되었습니까?

해결책

하나의 가능한 이유는 list.getItems () ( msdn ).놓친 경우 args.get_message ()에서 "알 수없는 오류"를 얻을 수 있습니다.
따라서 작업을 수행하려면 새 CamlQuery 개체를 초기화하고 코드를 다음과 같이 변경할 수 있습니다.

var context = new SP.ClientContext(appweburl);
var appContextSite = new SP.AppContextSite(context, hostweburl);
var list = appContextSite.get_web().get_lists().getByTitle('List1');
var query = new SP.CamlQuery();
itemsInlist = list.getItems(query);
context.load(itemsInlist);
context.executeQueryAsync(....)
.

쿼리에서 필터링 또는 정렬을 지원하려면 다음을 호출 할 수 있습니다.

query.set_viewXml("your caml");  
.

list.getItems (쿼리) 이전.목록 항목을 검색하는 방법에 대한 자세한 내용은 여기 .그것이 도움이되기를 바랍니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top