You need to sign in to do that
Don't have an account?
Nervosa
Datepicker with calendar in VF + Erasing content of inputText
Hi there! =)
Look what i've got! Here is my Apex class:
public class FullFunctionality { public String NewItemName {get; set;} public Integer NewItemQuantity { get; set; } public Integer NewItemPrice { get; set; } public String NewItemType { get; set; } public Date NewItemReleaseDate { get; set; } public List<SelectOption> getTypes(){ List<SelectOption> types = new List<SelectOption>(); Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry f : ple) { types.add(new SelectOption(f.getLabel(), f.getValue())); } return types; } public void add() { Item__c NewItem = new Item__c( Name = NewItemName, Item_Price__c = NewItemPrice, Items_Available__c = NewItemQuantity, Item_Type__c = NewItemType, Release_Date__c = NewItemReleaseDate); insert NewItem; } DisplayMerchandise[] products; public class DisplayMerchandise { public Item__c merchandise { get; set; } public DisplayMerchandise(Item__c item) { this.merchandise = item; } } public DisplayMerchandise[] getProducts() { if (products == null) { products = new DisplayMerchandise[]{}; for (Item__c item : [SELECT id, name, item_price__c, createddate, item_type__c FROM Item__c ]) { products.add(new DisplayMerchandise(item)); } } return products; } }
and here is my VF page:
public class FullFunctionality { public String NewItemName {get; set;} public Integer NewItemQuantity { get; set; } public Integer NewItemPrice { get; set; } public String NewItemType { get; set; } public Date NewItemReleaseDate { get; set; } public List<SelectOption> getTypes(){ List<SelectOption> types = new List<SelectOption>(); Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry f : ple) { types.add(new SelectOption(f.getLabel(), f.getValue())); } return types; } public void add() { Item__c NewItem = new Item__c( Name = NewItemName, Item_Price__c = NewItemPrice, Items_Available__c = NewItemQuantity, Item_Type__c = NewItemType, Release_Date__c = NewItemReleaseDate); insert NewItem; } DisplayMerchandise[] products; public class DisplayMerchandise { public Item__c merchandise { get; set; } public DisplayMerchandise(Item__c item) { this.merchandise = item; } } public DisplayMerchandise[] getProducts() { if (products == null) { products = new DisplayMerchandise[]{}; for (Item__c item : [SELECT id, name, item_price__c, createddate, item_type__c FROM Item__c ]) { products.add(new DisplayMerchandise(item)); } } return products; } }
There are two problems that i can't solve because of my inexperience:
1) How can i implement formatted input of ReleaseDate? It is desirable a calendar to be rendered when focus is on the corresponding inputText.
2) How can i clean all the inputText elements on my page when commandButton is down and new record is added successfully?
Thanks in advance.
Finally i've found the solution here - http://boards.developerforce.com/t5/Visualforce-Development/Refresh-Visualforce-Page/m-p/86101/highlight/true#M4439
All Answers
for date widget you can make create a standard object instance which contains date field in the class and make use of that..
or you can go with some thing like this
<apex:page >
<apex:form >
<table>
<td> Date<br></br><input id="t" name="date" onfocus="DatePicker.pickDate(false,
't', false);" size="12" tabindex="28" type="text" /><span class="dateFormat"> <a
href="javascript:DatePicker.insertDate('2/3/2011', 't', true);"
></a> </span></td>
</table>
</apex:form>
</apex:page>
i didn't get the second question..
I'm afraid this won't fit.
As far as i can see - there are no any methods in visualforce to do that and Javascript methods are inacceptable.
Maybe there is a way to make something like formatted input?
Concerning my second question - to make the long story short - i'd like to refresh(rerender) my vf page so that new item will be already displayed.
Please add your Visualforce Page code .I saw only apex code in your Post
Oops =))
Here it is:
1)First point using multiple forms is not a better approach
2)Kiran was right that we will have to use an already existing object instance to bring the Calendar picker
3)The question were you are about to rerender whole page i would recommend you to use Pagerefernce method returning null.This will solve your problem and already added line item will display.
Thank you for reply.
About refreshing my page. I added a method like this -
and then i invoke it in my add() method -
but still it doesn't work properly. What i did wrong?
Try this .
Also better is on Add method you collect in a list.Make a getter setter and collect in a list .You can insert at the last through submit button.For each Add button making a DML call is not good practice
This doesn't work =\
Also i can't get an idea you wrote in your next post. =(
Finally i've found the solution here - http://boards.developerforce.com/t5/Visualforce-Development/Refresh-Visualforce-Page/m-p/86101/highlight/true#M4439