javascript - Format value of form field -
i have edit form populated corresponding model. has text field has date value associated it. using javascript plugin allows user select date popup, shows nicely in field july 15, 2015
plugin submits hidden field format database expecting.
when go edit page field pre-populated ugly date format value , plugin doesn't update format of date when it's initialized, when user picks date. there way in cakephp can pre-format value before it's displayed page? if ran through javascript plugin handle format great.
my form field
echo $this->form->input('date', array( 'type' => 'text', 'class' => 'pickadate', 'placeholder' => 'pick date', 'required' => true ));
the plugin i'm using http://amsul.ca/pickadate.js/date/
$('.pickadate').pickadate format: 'mmmm dd, yyyy' formatsubmit: 'yyyy-mm-dd' hiddenname: true container: 'main'
update
in being pointed using controller format value before it's passed view here controller code i'm not sure that
public function edit($id = null) { if (!$this->meeting->exists($id)) { throw new notfoundexception('invalid meeting'); } if ($this->request->is(array('post', 'put'))) { if ($this->meeting->save($this->request->data)) { $this->session->setflash('the meeting has been saved.','default',array('class'=>'success'),'flash'); return $this->redirect(array('action' => 'index')); } else { $this->session->setflash('the meeting not saved. please, try again.','default',array('class'=>'error'),'flash'); } } else { $this->request->data = $this->meeting->find('first', array( 'conditions' => array( 'meeting.id' => $id, ), )); } $this->meeting->set('date', caketime::format($this->meeting->date, '%b %d, %y')); $meetingrooms = $this->meeting->meetingroom->find('list'); $users = $this->meeting->user->find('list'); $events = $this->meeting->event->find('list'); $this->set(compact('meetingrooms', 'users', 'events')); }
i figured out i'm setting data in $this->request->data
being sent view, changed code updates date this
$this->request->data['meeting']['date'] = caketime::format($this->request->data['meeting']['date'], '%b %d, %y');
Comments
Post a Comment