Clone a date element with javascript

mk13

New Member
hi,
I put a java code in a element. however does not work... the code seems to be not bad.
Can anyone help me ?
the method was really simple, I just wanted to crone a date value from A element to B element, when a element had filled in a value.
like : 2013-01-27 08:50 (start element) -> copy -> 2013-01-27 08:50 (end element).
the code was following and I had put this code in the start element. trigger was focus.
Code:
var check = form1.formElements.get('tableA___enddate_raw').getValue();
var start = form1.formElements.get('tableA___startdate_raw').getValue();
if ($check == '0000-00-00 00:00:00'){  // this is a condition when enddate had been empty
form1.formElements.get('tableA___enddate_raw').update(start);
}
the execution result, the value of end was ' 1970-01-01 ' it is not copy...

pls anyone !
 
Try,

Code:
var check = form1.formElements.get('tableA___enddate_raw').get('value');

and modify the following line to the same format. The .get('value') changed with one of the releases of mootools, which basically means you may fine examples on the forums with the old code style.
 
hi, Unfortunately ended in failure.:mad:
Course did remove the IF statement.
Reported hasten .
 

Attachments

  • stop.png
    stop.png
    64.4 KB · Views: 234
  • error.png
    error.png
    52.2 KB · Views: 265
There appears to be a problem with the date element at the moment which has prevented me from testing this further. I have changed the code but will need to revert back a couple of revisions to test it.

Meanwhile have a look at these posts.... you may have to change the 'getvalue' format that I mentioned earlier.

http://fabrikar.com/forums/showthread.php?t=12958

http://fabrikar.com/forums/showthread.php?t=12959


http://fabrikar.com/forums/showthread.php?t=12960


Something like...

Code:
var check = $('usertest___date1').get('value');
var start = $('usertest___date2').get('value');

...should work for your first two lines.

As you are already inside an element I don't think you need the 'form1.formElements.get', which by the way I think should be 'form_1.formElements.get'.

http://fabrikar.com/wiki/index.php/Form_and_element_javascript


If I get the date element working I don't mind having another look if you don't work it out. :)



 
well to start with you assign the date to the variable 'check' and then you use the variable '$check' in the if statement, these won't contain the same values :)
Use 'check' in the if statement and see if that works
 
hi, rob give me to reply on busy , thank u.

I v tried to use 'check'. however it does not work correctly. when I click all other date elements that is not related this method gave me a reaction like: ' date: invalid date time : NaN:NaN ' .

Firebug tell me attached a break point and some error described above.:cool:
 

Attachments

  • breakpoint.png
    breakpoint.png
    53.6 KB · Views: 201
  • t1.png
    t1.png
    12.8 KB · Views: 207
hello

I v looked around date.js.
Whether or not, date.js seems to make a instance for get a value of date when we use calendar object .(line241)
So we might get the variable from this instance, when I make a clone ? if so that, how to get it....;D
 
first if you are debugging js its best to turn Joomla's global config debug site option on, that way you get to see the uncompressed versions of the js files, making debugging a whole lot easier.


the date.js class's getValue() method gets the date from the calendar object (which is how we want things as the value in the field may be formatted in in such as way as to make parsing the string into a date a bit complex.

Another thing I noticed is that you were trying to get tableA___startdate_raw, but that key won't exist in n the form's formElements object, you should thus remove the '_raw' from that. I've had a go at writing something below which to me looks correct, although I have not tested it:

Code:
var elements = Fabrik.blocks['form_1'].formElements;
var startDateElement = elements.get('tableA___startdate');
var endDateElement = elements.get('tableA___enddate');
var startDate = startDateElement.getValue();
if (startDate !== '0000-00-00 00:00:00') {
  endDateElement.update(startDate):
}
 
first if you are debugging js its best to turn Joomla's global config debug site option on, that way you get to see the uncompressed versions of the js files, making debugging a whole lot easier.
I got used to a little smarter?:)
the date.js class's getValue() method gets the date from the calendar object (which is how we want things as the value in the field may be formatted in in such as way as to make parsing the string into a date a bit complex.
Yeah, it looks like complex, cheese have worked harder. Otherwise I m looking forward to grow up a something about the date function. because the case that hook the date element is not a few thing. I used to filter the date. I also wanted to do compare an another date (now, a date in the same record, a date in the another records) or how many days between dateA to date B, etc, the latter require would treat as PHP, Well, whatsoever I felt thing seems high Frequency sort of.

Redundancy, Fabrik Calendar Visualazation is perfect for me. I never seen such a calendar anywhere. ;) So I wish to grow up, too. thank u very much
Another thing I noticed is that you were trying to get tableA___startdate_raw, but that key won't exist in n the form's formElements object, you should thus remove the '_raw' from that. I've had a go at writing something below which to me looks correct, although I have not tested it:
Code:
var elements = Fabrik.blocks['form_1'].formElements;
var startDateElement = elements.get('tableA___startdate');
var endDateElement = elements.get('tableA___enddate');
var startDate = startDateElement.getValue();
if (startDate !== '0000-00-00 00:00:00') {
  endDateElement.update(startDate):
}
I also wanted to copy the time as well as date. so I added the '_raw'
Anyway I m gonna try to do this. thanks a lot.;)
 
Giveing up about this. So I use this code.
Code:
$('jos_occt_training___end_date_cal').value =$('jos_occt_training___train_start_date_cal').getValue();
However it is wondering to be not worked for the code of wiki base.....
 
mk13 is rising up.
PHP:
$begin=JRequest::getVar('db_event___begin_raw',post);
 defined ('_JEXEC') or die ('Restricted access');
 return $formModel->updateFormData('db_event___date_dummy_raw',$begin,true);
I should have ask you when it completes the clone. In my case, It was all right after submitting. Therefore I was able to chose to the way to php stuff.

Thank u
 
I think that might add the strtotime statement to above, coz the copy has a GAP against original element. Or the part of time element can not be able to copy it.
 
Code:
$('jos_occt_training___end_date_cal').value =$('jos_occt_training___train_start_date_cal').getValue();
Hellow, this code was working under the JS tab for a while ago.Even if the trigger was 'onchange'. But for now does not work.
Q1) Anything is changing ?
Q2) Or Shoud I use DOM and JS for now ?
I am really confusing about handling the date element(JavaScript) ,Please advice me.

For instance, Suppose to get a value of default with php code, then I set the eval of default, but it would not be get the flying date value, even if it was later of submitting.
Q3) We can see the clone plugin under /plugins/fabrik_form/clone. Is this available for only cloning ?

So I have to use javascript. I am writing like below:
What I want:
1) Populating from 'E1' to 'E2' in creating NEW record.
2) Transforming against 'E1'
e.g. E1 [2012-05-24 13:00] => E2 [2012-5-17] --- Transform to 7days ago

Enviroment:
- One list has three elements(E1,E2) which is grouped by one group.
- E1, is type of Date, E2 is type of Field.
- E1 has set a default value with the current datetime.
- Where: JSplugin-tab in 'E2'
- Trigger: keyup || focus || onchange
- Stage: by firing

Code:
var base=$('tbl_name___E1_cal').getValue;
var td=new Date(base);
td.setTime(td.getTime(td)-(7*24*3600*1000));
$('tbl_name___E2_cal').value = td.getValue;
I think this would be wrong at somewhere, but I can not know it.
 
This also does not work. trigger was focus,keyup,change, in JS tab.
var elements=Fabrik.blocks['form_1'].formElements;
var el1=elements.get('db_event___begin_cal');
var el2=elements.get('db_event___end_cal');
var beginDate=el1.getValue();
el2.update(beginDate);
 
I though the new mootools meant that you have to do this now...


Code:
var beginDate=el1.get('value')
... but I did mention that on page1 in January, but you said it didn't work... but I think that was to do with the date problems.

Hugh \ Rob are the JS experts so I'll let them comment. :)
 
Yeah,
I have get back to cloning again and tested it for knowing the habit to work or not.
but not work...
var elements=Fabrik.blocks['form_1'].formElements;
var el1=elements.get('db_event___begin_cal');
var el2=elements.get('db_event___end_cal');
var clone=el1.get('value');
el2.update(clone);

var elements=Fabrik.blocks['form_1'].formElements;
var el1=elements.get$('db_event___begin_cal');
var el2=elements.get$('db_event___end_cal');
var clone=el1.get$('value');
el2.update(clone);
And I found out below for only cloning. I am going to do this someday.
http://mootools.net/docs/core/Element/Element#Element:clone
And I will think about this.
http://fabrikar.com/forums/showthread.php?t=26281&highlight=date+function
 
Hellow, this code was working under the JS tab for a while ago.Even if the trigger was 'onchange'. But for now does not work.

Q1) Anything is changing for using a JS?
- coz : Calling a event changed ? Fabrik3 form javascript
- coz : ${listname___element_cal} became to not be Grobal Variable ?

Q3) We can see the clone plugin under /plugins/fabrik_form/clone. Is this available for only cloning anything of date?

Q4) What the rules shoud I obey for using Javascript on case by case ?
case1 : including form_x.js -> One of answer. mootools hash object ?
case2 : javascript-tab in the element
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top